2011-09-25 100 views
2

我想删除一些数据库条目,每个条目都有唯一的ID。我当前的代码看起来是这样,从这里取:Zend Framework: How to delete a table row where multiple things are true?Zend_Db_Table:删除多个条目

$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的正常工作,这并不当然的工作,但我怎么能得到这个工作呢?

回答

12

试试这个:

$where = $this->getAdapter()->quoteInto('id IN (?)', $IDs); 
$this->delete($where);