在 Zend 中使用 IN 运算符的“更新语句”不正确
我有一个函数想要执行如下所示的语句:
UPDATE coupon_users SET status = status | '1' WHERE id IN ('3','4')
在 coupon_users 模型中,我编写了如下方法:
/**
* @param array $ids #array(3,4)
* @param array $status #1
*/
public function updateStatus(array $ids, $status)
{
$result = $this->_db->query(
"UPDATE {$this->_name} SET status = status | ? WHERE id IN (?)",
array(
$status,
$ids
)
)->execute();
return $result;
}
但查询始终是:
UPDATE coupon_users SET status = status | '1' WHERE id IN ('Array')
我不知道我错了什么在此,请帮助我,非常感谢。
I have a function which is wanted to execute a statement like below:
UPDATE coupon_users SET status = status | '1' WHERE id IN ('3','4')
And in coupon_users
model, I wrote a method like below do to:
/**
* @param array $ids #array(3,4)
* @param array $status #1
*/
public function updateStatus(array $ids, $status)
{
$result = $this->_db->query(
"UPDATE {$this->_name} SET status = status | ? WHERE id IN (?)",
array(
$status,
$ids
)
)->execute();
return $result;
}
But the query is always:
UPDATE coupon_users SET status = status | '1' WHERE id IN ('Array')
I don't know what am I wrong here, please help me, many thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
根据PDO文档(Zend_Db使用PDO作为其数据库访问后端) :
因此,您可能需要进一步准备查询,以便它包含与数组中的元素一样多的标记。可能的解决方案如下:
希望有所帮助,
According to the PDO documentation (Zend_Db uses PDO as its DB access backend):
So, you'll probably need to prepare a bit further your query, so that it contains as many markers as elements in the array. A possible solution could be the following:
Hope that helps,
尝试:
更新:
你尝试过吗?:
的实例
我还没有测试过,它还取决于 $this->_db 是http://framework.zend.com/manual/en/zend.db.adapter.html#zend.db.adapter.write.update
try:
Update:
Have you tried?:
I haven't tested it, it also depends on what $this->_db is an instance of
http://framework.zend.com/manual/en/zend.db.adapter.html#zend.db.adapter.write.update
试试这个..
Try this..
它对我来说工作得很好。
Its working fine for me.