Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exporting MYSQL data into Excel/CSV via php

i want to Export MYSQL data into Excel/CSV via php. so that i can use my database later or someone can use and understand it.

like image 442
Mert Yigin Avatar asked Oct 09 '11 19:10

Mert Yigin


People also ask

Can you export data from MySQL to excel?

Data can be imported from MySQL into a Microsoft Excel spreadsheet by using the Import MySQL Data option after selecting either a table, view, or procedure to import. First of all, you do the first 6 steps describe above in "Edit MySQL Data in Excel" then select your table which you want to import.


1 Answers

To create a .CSV file with syntax suitable for EXCEL you can use basic SQL:

SELECT * FROM mytable
INTO OUTFILE '/mytable.csv'
FIELDS ESCAPED BY '""'
TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\r\n';

See the manual here.

like image 195
Erwin Brandstetter Avatar answered Oct 20 '22 16:10

Erwin Brandstetter