Query mysql and export data as CSV in PHP -


i have myssql db different tables. data between tables linked , retrieve , display them using userid. used reference php mysqli displaying tables in database

but how export information csv file? have tried instead of echo changed string , print string csv file not working.

i have tried example from: http://sudobash.net/php-export-mysql-query-to-csv-file/

but can see data on top there junk (like "<font size='1'><table class='xdebug-error xe-notice' dir='ltr' border='1' cellspacing='0' cellpadding='1'>"
etc) inside csv file.

is there way this?

if want write each mysql row csv file, use built in php5 function fputcsv

$result = mysqli_query($con, 'select * table'); $row = mysqli_fetch_array($result, mysqli_assoc);  $fp = fopen('file.csv', 'w');  foreach ($row $val) {     fputcsv($fp, $val); }  fclose($fp); 

which should return comma separated string each row written file.csv:

row1 val1, row1 val2 row2 val1, row2 val2  etc.. 

also sure check permissions directory writing to.


Comments