2012-04-20 84 views
1

嗨,我需要做一個簡單的查詢,但有些錯誤。我有$ name和$姓,我需要搜索該rappresent這個名字和姓氏(可能多個)的ID,並把所有的ID,姓名一個數組中 我做這個查詢:Zend查詢選擇

$result=$this->_db_table->select()->where('name=?',$name) 
    ->where('surname=?', $surname)->query() 
    ->fetchAll(); 

$array=$result->toArray(); 
return $array; 

如果我使用

$result=$this->_db_table->fetchAll(); 
$array=$result->toArray(); 
return $array 

它工作正常,我有一個數組whith在該表中的數據庫中的所有值。我的第一個代碼有什麼問題?

回答

1

這樣

$result=$this->_db_table->select()->where('name=?',$name) 
    ->where('surname=?', $surname)->query() 
    ->fetchAll(); 

$結果後,已經是一個數組它不是一個對象。所以只需使用它而不是調用toArray就可以了。

正確的代碼WD是

$result=$this->_db_table->select()->where('name=?',$name) 
    ->where('surname=?', $surname)->query() 
    ->fetchAll(); 

return $result;