Problem in Export csv file in php
I need to export csv file in php using mysql query .But when i export filename like this "yourfilename.csv_".
My code is
header("Content-type: application/csv");
header("Content-Disposition: \"inline; filename=yourfilename.csv\"");
$query = "SELECT * FROM login";
$result = mysql_query($query) ;
echo "username ,password \r\n";
while($row = mysql_fetch_array($result))
{
echo "$row[user],$row[pass]\r开发者_如何学JAVA\n";
}
I need file name "yourfilename.csv".
You can have MySql return a query result to file directly with
SELECT * INTO OUTFILE 'result.csv'
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY '\n'
FROM my_table;
and then just do (also see Example #1 Download dialog)
header('Content-type: text/csv');
header('Content-Disposition: attachment; filename="yourfilename.csv"');
readfile('result.csv');
精彩评论