开发者

Zend DB fetchAll(): where clause array with IN operator

开发者 https://www.devze.com 2022-12-20 06:53 出处:网络
I\'m selecting records from a database using the equivalent of this query: SELECT * FROM reports WHERE user_id IN (3, 6, 22);

I'm selecting records from a database using the equivalent of this query:

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

The function calling fetchAll() has an argument that's an array of the user IDs, and this call works just fine:

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

However, I would like to use an array for the where clause because there will probably be other restrictions to the query later... and I can't figure it out for the life of me. I thought it would be some variation on the following:

$resultSet = $this->getD开发者_JAVA百科bTable()->fetchAll(array('user_id IN ?' => '(' . implode(', ', $userIds) . ')'));

But so far no dice. Can someone provide the correct syntax here?


$data = array(1, 2, 3);
$select->where('user_id IN (?)', $data);


In Zend 2

$data = array(1, 2, 3);
$select->where('user_id', $data);


$select = $this->getSql()->select();
$select->where("reports.user_id in ('3','6','22')"); 
$resultSet = $this->selectWith($select);             
//echo $select->getSqlString();die;
return $resultSet;
0

精彩评论

暂无评论...
验证码 换一张
取 消