I want to export my database to an excel file by php,I need a source code in php to do this
3 Answers
I'm not going to write your whole program for you (that's not what this site is about) but if you have a specific problem, feel free to post another question.
It looks like PHP has a built-in function to export an array to a line in a CSV file: fputcsv
. So run your query and for each row returned, call fputcsv
.
Or, just use mysqldump
which claims to support dumping to natively support dumping a database to CSV.

- 51,711
- 9
- 123
- 115
PLEASE NOTE!
Exporting Records to .csv is not the same as exporting records to MX Excel .csv.
First and foremost, the source code is out there. Not problem finding it.
The difference though is with Excel, with you are separating with commas and encapsulating with ", Excel escapes quotes (") with an additional quote (so it looks like "").
This means you can't simply use addslashes when trying to export.

- 6,503
- 4
- 31
- 38
This is not meant any harm. If you need the sourcecode for an CSV export (lot of code available at php.net) the phpBlocks is maybe the right tool for you. Export to CSV without coding. Click&Point like Google's AppInventor.

- 11,432
- 6
- 35
- 51

- 11
- 1