CodeIgniter Forums
$query->row() returns array ALWAYS - 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: $query->row() returns array ALWAYS (/showthread.php?tid=30541)



$query->row() returns array ALWAYS - El Forum - 05-18-2010

[eluser]kmanlove[/eluser]
If I do something like
Code:
$query = $this->db->get($this->table, $this->limit, $this->offset);        
return $query->row();
and that certain get() doesn't actually find a record (doesn't exist, for instance), row() returns an array.

I can't think of a time when I would ever want it return an array instead of an object just because it's empty.

Even if specify through row(0, 'object'), it still comes back as an empty array instead of an empty object. I've looked at DB_result.php and can't find where this is happening. Any help with this would be great. Maybe I'm missing something.

Thanks,
Keith


$query->row() returns array ALWAYS - El Forum - 05-18-2010

[eluser]WanWizard[/eluser]
DB_result.php, line 72.


$query->row() returns array ALWAYS - El Forum - 05-18-2010

[eluser]kmanlove[/eluser]
OK, I see. Am I wrong in thinking that it should be an empty stdClass?


$query->row() returns array ALWAYS - El Forum - 05-18-2010

[eluser]WanWizard[/eluser]
No, the result_object() method should return an object, not an array. So this is a bug.

You could debate if either an array or object should be returned if you request something that doesn't exist.
I would prefer FALSE, to make it easier to test the result of a $query->row() call. Now it returns an array, and you have to test if it's empty to avoid errors about missing array elements (or in your case, getting an array back instead of an object).