Saad Bashir
Saad Bashir

Reputation: 4519

Can't Find File Created By OUTFILE

I am trying to save contents of the table 'dbtable' into a csv file using OUTFILE method. It doesn't give me any error and I am unable to find the file either. I have tried without defining the path and using 'mydata.csv' only too. But same result. I am using wamp on Windows 10.

mysqli_query($con,"SELECT * FROM dbtable INTO OUTFILE 'C:\mydata.csv' FIELDS ESCAPED BY '\"' TERMINATED BY ',' ENCLOSED BY '\"' LINES TERMINATED BY '\n' ");

Upvotes: 3

Views: 442

Answers (2)

Saad Bashir
Saad Bashir

Reputation: 4519

Apparently the issue was with path. It is not taking absolute path 'C:\' instead when I used relative path it worked. Earlier it was saving in /bin/mysql/data/ folder when saved without any path but using ../../../www/ enabled me to bring it to my www folder.

Upvotes: 2

GrumpyCrouton
GrumpyCrouton

Reputation: 8621

Try this:

mysqli_query($con,"SELECT * FROM dbtable INTO OUTFILE 'C:\mydata.csv' FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\"' LINES TERMINATED BY '\n'");

The main differences are I removed "FIELDS ESCAPED BY" as "OPTIONALLY ENCLOSED BY" should take care of that. I found very few examples where "FIELDS ESCAPED BY" worked.

Upvotes: 1

Related Questions