Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if Zend select returns a result or not

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!
}
like image 848
rjmcb Avatar asked Feb 23 '12 07:02

rjmcb


3 Answers

$rows = $this->fetchAll();
return (!empty($rows)) ? $rows : null;
like image 191
coolguy Avatar answered Oct 18 '22 18:10

coolguy


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;
    }
like image 27
RockyFord Avatar answered Oct 18 '22 18:10

RockyFord


I've found this way and works fine for me :

if($result->count() > 0) {
    //Do something
}

Thanks to Åsmund !

like image 4
Lano Avatar answered Oct 18 '22 19:10

Lano