Reputation: 3745
In Zend framework, how do I check if zend_db_select
returns a result or not?
$result = $this->fetchAll();
is there a better way rather than using:
if(count($result) != 0){
//result found!
}
Upvotes: 7
Views: 7489
Reputation: 643
I've found this way and works fine for me :
if($result->count() > 0) {
//Do something
}
Thanks to Åsmund !
Upvotes: 4
Reputation: 1251
The method return NULL, not FALSE. Check for this value using a if condition.
Upvotes: 1
Reputation: 8519
I like to use the classic:
//most of these queries return either an object (Rowset or Row) or FALSE
if (!$result){
//do some stuff
} else {
return $result;
}
Upvotes: 6
Reputation: 7954
$rows = $this->fetchAll();
return (!empty($rows)) ? $rows : null;
Upvotes: 10