0

I have a table with over a million rows. The PHP export script with headers and ajax that I normally use to create the user interface to export to csv, is not able to handle these many rows and times out. Hence looking for an alternative

After a fews days of digging I collated the below script from the internet, this downloads wonderfully but only to the local server > mysql folder

What I am looking for is to create a php mysql script so I can let users download large tables to csv's through the php user interface itself

SELECT 'a', 'b', 'c' UNION ALL SELECT a,b,c INTO OUTFILE '2026.csv' FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY '\n' FROM table ;

1 Answers1

1

You need to fetch from the DB with paginated results.

Select * from a LIMIT 0,100; the result of this query you must put in in a variable, then parse it like this:

Export to CSV via PHP

After you put the first 100 elements to the csv, you have to fetch from 100 to 200 and so on...then to reopen the csv and put the 100 to 200 elements and so on.

And then finally send the csv to the user.

MihaiM
  • 179
  • 6