Zend 查询选择 [英] Zend Query Select

查看:22
本文介绍了Zend 查询选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要做一个简单的查询,但出了点问题.我有 $name 和 $surname,我需要搜索表示该姓名和姓氏的(可能的多个)ID,并将所有 ID、姓名和姓氏放在一个数组中我做这个查询:

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;

如果我使用

$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???

推荐答案

做完之后

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

$result 已经是一个数组,而不是一个对象.所以只需使用它而不是调用 toArray 就可以了.

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

正确的代码 wd 是

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

return $result;

这篇关于Zend 查询选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆