我想删除一些数据库条目,每个条目都有一个唯一的ID。我现在的代码看起来是这样的,取自Zend Framework: How to delete a table row where multiple things are true?
$where = array();
foreach ($IDs as $ID) {
$where[] = $this->getAdapter()->quoteInto('id = ?', $ID);
}
$this->delete($where);
这是在Zend_Db_Table_Abstract扩展的模型类中调用的。 查询现在看起来像这样:
DELETE FROM `shouts` WHERE (id = '10') AND (id = '9') AND (id = '8')
当然,由于AND
,这不起作用,必须OR
才能正常工作,但我怎么能这样做呢?
答案 0 :(得分:12)
试试这个:
$where = $this->getAdapter()->quoteInto('id IN (?)', $IDs);
$this->delete($where);