3

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' ");
Dharman
  • 30,962
  • 25
  • 85
  • 135
Saad Bashir
  • 4,341
  • 8
  • 30
  • 60

2 Answers2

2

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.

Saad Bashir
  • 4,341
  • 8
  • 30
  • 60
1

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.

GrumpyCrouton
  • 8,486
  • 7
  • 32
  • 71