i’ve run into a curious problem with codeigniter’s odbc driver.
i’m connecting from a linux machine to an MSSQL 2008 machine using FreeTDS.
while i get that the ‘num_rows’ function always returns -1, and that is fully a database/driver issue – for some reason when i try to create a ->result(), the whole application crashes (error 500, sometimes just a blank page), if i’m lucky, i get an error message informing me that the application died because it tried to allocated 2 terrabytes of memory(!).
This happens irregularly, ie: every few refreshes. sometimes it runs fine, sometimes the page returns error 500 and sometimes it gives the memory allocation error – in any case it’s not really something that can be reproduced with percision, and the queries are SUPER simple.
ideas anyone?
Ha ha, this happend to me too! And I’ve complained to the devs about it, and they ignored me.
When you call result(), it will loop through every single possible result, and store the record into a massive internal array. See
system/database/DB_result.phpwhile loop at the end of result_object() and result_array()There are three ways of fixing it.
The easy way:
LIMIT(orTOPin MSSQL) your results in the SQL query.The UPDATED unbuffered way:
Use the
unbuffered_row()function that was introduced 2 years after this question was asked.The hard way:
Use a proper result object that uses PHP5 iterators (that the devs don’t like because it excludes php4). Slap something like this in your DB_result.php file:
Then to use it, instead of calling
$query->result()you use just the object without the->result()on the end like$query. And all the internal CI stuff still works withresult().By the way, my Iterator code working with their code has some logic problems with the whole -1 thing, so don’t use both
$query->result()and$queryon the same object. If someone wants to fix that, you are awesome.