CodeIgniter Forums
unbuffered_row() not working - returning null - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Development (https://forum.codeigniter.com/forumdisplay.php?fid=6)
+--- Forum: Issues (https://forum.codeigniter.com/forumdisplay.php?fid=19)
+--- Thread: unbuffered_row() not working - returning null (/showthread.php?tid=78774)



unbuffered_row() not working - returning null - JamesZXCVBNM - 03-09-2021

I'm having trouble with the unbuffered_row() function which doesn't seem to be working at all in CI_VERSION = 3.0.6

In this snippet, the die() never triggers (even though there are definitely results)

PHP Code:
    $sql "SELECT * FROM some_table";
    $query $this->db->query($sql);
    while ($row $query->unbuffered_row()) {
        die('here');
    

In this example, the var_dump returns NULL

PHP Code:
    $sql "SELECT * FROM some_table";
    $query $this->db->query($sql);
    var_dump($query->unbuffered_row()); 

I've followed the documentation, brief as it is on the subject. Is this a bug in the framework or am I missing something obvious?


RE: unbuffered_row() not working - returning null - iRedds - 03-09-2021

The method can return false or null if there are any errors in the request or an empty result.
Depends on the type of driver selected.
Null can be returned by sqlsrv and mysqli drivers

Try to query the database using native php functions to check.


RE: unbuffered_row() not working - returning null - JamesZXCVBNM - 03-09-2021

(03-09-2021, 08:55 AM)iRedds Wrote: The method can return false or null if there are any errors in the request or an empty result.
Depends on the type of driver selected.
Null can be returned by sqlsrv and mysqli drivers

Try to query the database using native php functions to check.

Thanks for the reply. There is definitely data returned by the query. If I do a result() instead:

PHP Code:
$this->db->query($sql)->result() 

It returns results (except I have to increase `memory_limit` to actually avoid memory exhausted errors)


RE: unbuffered_row() not working - returning null - iRedds - 03-09-2021

I will show you how it works so you can understand.

Call result()
result() -> result_object() -> _fetch_object() -> working with native php DBSM function

Call unbuffered_row()
unbuffered_row() -> _fetch_object() -> working with native php DBSM function

That is, the only difference is in result_object(), where _fetch_object() is called in a loop.