开发者

How to get a one click downloadable csv/excel file from a mysql database?

I have a mysql connection open and want to export all the data into a downloadable csv or excel file. I suspect that it has something to do with Select (http://dev.mysql.com/doc/refman/5.0/en/sele开发者_开发问答ct.html) but cannot get together syntax that works. Any pointers are appreciated.


I saw this for the first time the other day, and it is pretty awesome.

SELECT * INTO OUTFILE "/csvs/my-csv.cvs"
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY "\n"
FROM whatever;

Then link them to /csvs/my-csv.cvs, or force a download with PHP.

<?php
header('Content-type: text/csv');

header('Content-Disposition: attachment; filename="file.csv"');

readfile('/csvs/my-csv.csv');

exit;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜