Reputation:
So, I have a PHP that goes through a large table in DB, then when I get the results I put them into CSV. But the table keeps growing and now I got error that allowed memory size is exhausted.
SELECT column1, column2, column3 FROM table
And due to the size of table I can not put it into csv. How could I reduce the size of this query? Should I use LIMIT and then just put it into 2 halves?
Upvotes: 0
Views: 104
Reputation: 153
If you are writing to CSV, use fopen/fwrite to keep a stream instead of trying to concat to a string (which will cause out of memory fast if it's large), for the database query itself, using the _fetch_array() you can keep the result active on the server whilst only retrieving row by row from PHP.
This should keep the memory usage quite low.
Upvotes: 2