14

我正在使用此查询的等效项从数据库中选择记录:

SELECT * FROM reports WHERE user_id IN (3, 6, 22);

调用 fetchAll() 的函数有一个参数是用户 ID 的数组,这个调用工作得很好:

$resultSet = $this->getDbTable()->fetchAll('user_id IN (' . implode(', ', $userIds) . ')');

但是,我想为 where 子句使用一个数组,因为稍后查询可能会有其他限制……而且我一生都无法弄清楚。我认为这将是以下方面的一些变化:

$resultSet = $this->getDbTable()->fetchAll(array('user_id IN ?' => '(' . implode(', ', $userIds) . ')'));

但到目前为止还没有骰子。有人可以在这里提供正确的语法吗?

4

3 回答 3

21
$data = array(1, 2, 3);
$select->where('user_id IN (?)', $data);
于 2010-02-17T21:02:23.887 回答
2

在 Zend 2

$data = array(1, 2, 3);
$select->where('user_id', $data);
于 2014-01-23T18:06:55.207 回答
0
$select = $this->getSql()->select();
$select->where("reports.user_id in ('3','6','22')"); 
$resultSet = $this->selectWith($select);             
//echo $select->getSqlString();die;
return $resultSet;
于 2016-08-08T10:04:34.233 回答