Zend_Db_Table: Delete multiple entries

醉酒当歌 提交于 2019-12-06 10:23:45

问题


I wanted to delete some db entries and each of them has a unique ID. My current code looks so, taken from here: 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);

This is called inside the model class extends by Zend_Db_Table_Abstract. The query looks now like that:

DELETE FROM `shouts` WHERE (id = '10') AND (id = '9') AND (id = '8')

That doesn't work of course because of the AND's, this have to be OR's to work correctly, but how could I get this work so?


回答1:


Try this:

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


来源:https://stackoverflow.com/questions/7549217/zend-db-table-delete-multiple-entries

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!