Zend Query Select

岁酱吖の 提交于 2019-12-11 04:19:20

问题


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:


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;


来源:https://stackoverflow.com/questions/10242185/zend-query-select

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!