Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/silverlight/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Zend framework Zend DB fetchAll():其中为数组_Zend Framework_Zend Db Table - Fatal编程技术网

Zend framework Zend DB fetchAll():其中为数组

Zend framework Zend DB fetchAll():其中为数组,zend-framework,zend-db-table,Zend Framework,Zend Db Table,我不明白为什么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(); $wher

我不明白为什么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();
有点失望,我是不是错过了什么

因此您是不正确的,
fetchAll()
接受where子句数组

您的数组应该如下所示(基于中的定义)

因此您是不正确的,
fetchAll()
接受where子句数组

您的数组应该如下所示(基于中的定义)


首先,我们将查看您的原始代码:

$wheres = array('id > 0', 'enabled' => 1);
记住
=>
是赋值运算符。在上面的数组中,以自动分配给键
0
的字符串开始。下一个元素是分配给键的编号
1
“已启用”。答案1中提出的解决方案将编号
1
分配给键
“enabled=?”

试试这个:

$all = new ORM_Model_DbTable_Asset();
$where = array();
$where[] = 'id > 0';
$where[] = $all->quote_into('enabled >= ?', 1, 'INTEGER');  // 1 could be a variable
$result = $all->fetchAll($where);

首先,我们将查看您的原始代码:

$wheres = array('id > 0', 'enabled' => 1);
记住
=>
是赋值运算符。在上面的数组中,以自动分配给键
0
的字符串开始。下一个元素是分配给键的编号
1
“已启用”。答案1中提出的解决方案将编号
1
分配给键
“enabled=?”

试试这个:

$all = new ORM_Model_DbTable_Asset();
$where = array();
$where[] = 'id > 0';
$where[] = $all->quote_into('enabled >= ?', 1, 'INTEGER');  // 1 could be a variable
$result = $all->fetchAll($where);

我会避免用结果数组覆盖
$all
DB表对象我会避免用结果数组覆盖
$all
DB表对象为了使用此符号,$where不必是select()对象吗$其中=$this->select()$where->where(数组('id>0','enabled=?',1));或者类似的东西?@RockyFord当
fetchAll()
$where
(第一个)参数是数组时,内部会发生这种情况。要使用这种表示法,$where不一定是select()对象吗$其中=$this->select()$where->where(数组('id>0','enabled=?',1));或者类似的东西?@RockyFord当
fetchAll()
$where
(第一个)参数是数组时,内部会发生这种情况