Zend Query Select

2019-07-25 08:03发布

Hi i need to do a simple query but something is wrong. I have $name and $surname and i need to search the (possible multiple) id that rappresent that name and surname and put all the id, name and surname in a array I do this query:

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

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

If i use

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

it work correctly and i have an array whith all the value in the database in that table. What is wrong in my first code???

1条回答
别忘想泡老子
2楼-- · 2019-07-25 08:44

After doing this

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

$result is already an array its not an object . So simply use it instead of calling toArray on it.

Correct code wd be

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

return $result;
查看更多
登录 后发表回答