php中的$this-%3efetch,Zend DB fetchAll(): where子句數組帶有IN操作符

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;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值