2012-02-23 60 views
5

在Zend框架中,如何检查zend_db_select是否返回结果?如何检查Zend select是否返回结果

$result = $this->fetchAll(); 

有没有更好的办法,而不是使用:

if(count($result) != 0){ 
    //result found! 
} 
+3

你在这里展示的方法有什么问题? – 2012-02-23 07:43:41

+0

我在找一个更好的方法。 – rjmcb 2013-07-03 07:23:19

回答

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

我喜欢用经典:

//most of these queries return either an object (Rowset or Row) or FALSE 
    if (!$result){ 
     //do some stuff 
    } else { 
     return $result; 
    } 
1

方法返回NULL,而不是FALSE。使用if条件检查此值。

2

我发现这种方式为我工作得很好:

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

感谢Åsmund

相关问题