Welcome Guest, Not a member yet? Register   Sign In
equivalent of while($row=mysql_fetch_
#1

Hi

When pulling large amounts of rows from a database to manipulate like when exporting to a spreadsheet, I am hitting memory limits because when you do something like

$query=$this->db->query("SELECT * FROM table");
foreach($query->result() as $row) {
// write to a spreadsheet
}

The initial $query has to load up all the data into memory in order to do the foreach loop as well as then store the data into more memory as I am manipulating it.

In the old days I would use

while($row=mysql_fetch_array($query)) {
// write to some file
}

and I wouldn't get memory limit issues because the while() loop would only load up enough data to use for each loop.

Basically, without having to use Offset and Limit, is there an equivalent in CI that lets me use a while loop to iterate through DB results and retrieve data as I am looping?

cheers
Scott.
Reply
#2

ah, I just found

while ($row = $query->unbuffered_row())
Reply




Theme © iAndrew 2016 - Forum software by © MyBB