I am trying to export sql query result to csv file it works but the out csv data does not look good and strange.
MySQL Table Download Link: https://www.dropbox.com/s/vtr215bcxqo3wsy/data.sql?dl=0
CSV Generated by sql query:
Download Link to original Generated CSV File: https://www.dropbox.com/s/fnjf7ycmh08hd22/data.csv?dl=0
I am using following code:
$query = <<<EOL
SELECT * FROM data ORDER BY FN ASC limit 3
INTO OUTFILE 'folder/data.csv'
FIELDS TERMINATED BY ','
OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY '\n'
EOL;
$result = mysql_query($query);
Why csv format is looking so weird and unacceptable? If I try same code for some other table then everything works like charm then what's wrong?
\n, any\ninside your fields terminate that "row".fields escaped by '\\', see if that escapes the literal\ninto\\n. otherwise you'll probably need str_replace and convert the linebreaks into something else (maybe html<br>?)