rjmcb
rjmcb

Reputation: 3745

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!
}

Upvotes: 7

Views: 7489

Answers (4)

Lano
Lano

Reputation: 643

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

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

Thanks to Åsmund !

Upvotes: 4

Web_Developer
Web_Developer

Reputation: 1251

The method return NULL, not FALSE. Check for this value using a if condition.

Upvotes: 1

RockyFord
RockyFord

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

coolguy
coolguy

Reputation: 7954

$rows = $this->fetchAll();
return (!empty($rows)) ? $rows : null;

Upvotes: 10

Related Questions