本文共 1237 字,大约阅读时间需要 4 分钟。
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:
調用fetchAll()的函數有一個參數,它是一個用戶id的數組,這個調用可以正常工作:
$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:
但是,我想為where子句使用一個數組,因為以后查詢可能會有其他限制……我也不知道這是怎么回事。我認為這將是一些變化如下:
$resultSet = $this->getDbTable()->fetchAll(array('user_id IN ?' => '(' . implode(', ', $userIds) . ')'));
But so far no dice. Can someone provide the correct syntax here?
但到目前為止還沒有機會。有人能提供正確的語法嗎?
3 个解决方案
#1
21
$data = array(1, 2, 3);
$select->where('user_id IN (?)', $data);
#2
2
In Zend 2
在Zend 2
$data = array(1, 2, 3);
$select->where('user_id', $data);
#3
0
$select = $this->getSql()->select();
$select->where("reports.user_id in ('3','6','22')");
$resultSet = $this->selectWith($select);
//echo $select->getSqlString();die;
return $resultSet;
转载地址:http://cknva.baihongyu.com/