Welcome Guest, Not a member yet? Register   Sign In
unbuffered_row() not working - returning null
#1

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?
Reply
#2

(This post was last modified: 03-09-2021, 08:57 AM by iRedds.)

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.
Reply
#3

(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)
Reply
#4

(This post was last modified: 03-09-2021, 01:27 PM by iRedds.)

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.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB