CodeIgniter Forums
Can CI's database class do this? (Memory Issues w/large data sets) - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Can CI's database class do this? (Memory Issues w/large data sets) (/showthread.php?tid=13924)



Can CI's database class do this? (Memory Issues w/large data sets) - El Forum - 12-11-2008

[eluser]Unknown[/eluser]
I am having a memory problem because the result from the database being returned is anywhere from 5k too 100k records(and about 20 varchar255 columns +). I need to loop through each record and do a bunch of stuff but anyway the memory hit is about 25MB on only a 7,500 record return. I finally found a way to do this but I had to stop using CI's database class and use mysql function directly which I do not want to do. Why this works is because it is only taking up memory 1 record at a time and replacing that memory on the next loop, CI's database class seems to create an array looping through ALL records and then you loop through CI's array/obj. Can I use CI'S database class to only loop through 1 record at a time like below so I don't have memory problems? Basically I need CI to not create an array of all the results initially.

while ($row = mysql_fetch_assoc($result))

Thanks for the help, if you need more info let me know.

-Danny


Can CI's database class do this? (Memory Issues w/large data sets) - El Forum - 12-11-2008

[eluser]Sarfaraz Soomro[/eluser]
Quote:Basically I need CI to not create an array of all the results initially.

First thought, you might want to run the query in a loop with limit set to 1 and offset incrementing, not a good approach IMO, maybe some one with more experience in this regard may enlighten us.