Zend DB fetchAll():作为数组
我很困惑为什么 Zend_DB 不接受 WHERE
子句数组 - 或者我错了?我做了以下工作:
$all = new ORM_Model_DbTable_Asset();
$wheres = array('id > 0', 'enabled' => 1);
$all = $all->fetchAll(implode(' AND ', $wheres))->toArray();
为了我所希望的:
$all = new ORM_Model_DbTable_Asset();
$wheres = array('id > 0', 'enabled' => 1);
$all = $all->fetchAll($wheres)->toArray();
有点令人失望,我错过了什么吗?
I'm confused as to why Zend_DB doesn't accept an array of WHERE
clauses - or am I incorrect? I have made the following work around:
$all = new ORM_Model_DbTable_Asset();
$wheres = array('id > 0', 'enabled' => 1);
$all = $all->fetchAll(implode(' AND ', $wheres))->toArray();
for what I hoped would be:
$all = new ORM_Model_DbTable_Asset();
$wheres = array('id > 0', 'enabled' => 1);
$all = $all->fetchAll($wheres)->toArray();
Slightly disappointing, am I missing something?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
来自
Zend_Db_Table_Abstract
所以你错了,
fetchAll()
确实接受一个 where 子句数组。您的数组应如下所示(基于
Zend_Db_Select 中的定义
)
From
Zend_Db_Table_Abstract
So you are incorrect,
fetchAll()
does accept an array of where clauses.Your array should look like this (based on the definition in
Zend_Db_Select
)首先,我们将查看您的原始代码:
记住
=>
是一个赋值运算符。在上面的数组中,您从自动分配给键0
的字符串开始。下一个元素是分配给键'enabled'
的数字1
。答案 1 中提出的解决方案将数字1
分配给键'enabled = ?'
。试试这个:
First we will look at your original code:
Remember that
=>
is an assignment operator. In your array above you start out with string automatically assigned to key0
. The next element is the number1
assigned to the key'enabled'
. The solution proposed in answer 1 assigns the number1
to key'enabled = ?'
.Try this: