我需要在 zend frawork 中运行查询。查询如下所示。
select * from users where role_id in (3,5) and emailID not in ('abc@abc.com', 'cba@cba.com');
我正在传递字符串
$whereString = role_id in (3,5) and emailID not in ('abc@abc.com', 'cba@cba.com');
到
$this->fetchList($whereString) // where $this is object of users
但是 fetchList() 函数只执行第一部分,即role_id in (3,5)
但不是第二部分,即emailID not in ('abc@abc.com', 'cba@cba.com');
fetchList() 的结果包含 'abc@abc.com' 和 'cba@cba.com'
fetchList() 是:
public function fetchList($where=null, $order=null, $count=null, $offset=null)
{
$resultSet = $this->getDbTable()->fetchAll($where, $order, $count, $offset);
$entries = array();
foreach ($resultSet as $row)
{
$entry = new Application_Model_Users();
$entry->setId($row->id)
->setName($row->name)
->setEmail($row->email)
$entries[] = $entry;
}
return $entries;
}
获取所有():
/**
* Fetches all rows.
*
* Honors the Zend_Db_Adapter fetch mode.
*
* @param string|array|Zend_Db_Table_Select $where OPTIONAL An SQL WHERE clause or Zend_Db_Table_Select object.
* @param string|array $order OPTIONAL An SQL ORDER clause.
* @param int $count OPTIONAL An SQL LIMIT count.
* @param int $offset OPTIONAL An SQL LIMIT offset.
* @return Zend_Db_Table_Rowset_Abstract The row results per the Zend_Db_Adapter fetch mode.
*/
public function fetchAll($where = null, $order = null, $count = null, $offset = null)
{
if (!($where instanceof Zend_Db_Table_Select)) {
$select = $this->select();
if ($where !== null) {
$this->_where($select, $where);
}
if ($order !== null) {
$this->_order($select, $order);
}
if ($count !== null || $offset !== null) {
$select->limit($count, $offset);
}
} else {
$select = $where;
}
print_r($select);
$rows = $this->_fetch($select);
$data = array(
'table' => $this,
'data' => $rows,
'readOnly' => $select->isReadOnly(),
'rowClass' => $this->getRowClass(),
'stored' => true
);
$rowsetClass = $this->getRowsetClass();
if (!class_exists($rowsetClass)) {
require_once 'Zend/Loader.php';
Zend_Loader::loadClass($rowsetClass);
}
return new $rowsetClass($data);
}
任何人都知道我做错了什么。