Zend framework Zend DB fetchAll():其中为数组
我不明白为什么Zend_DB不接受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
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
(第一个)参数是数组时,内部会发生这种情况