通常,这个对我来说是有效的:
$db = Zend_Db_Table::getDefaultAdapter();
$where = $db->quoteInto('id = ?', $id);
$db->delete('tablename', $where);
但我需要匹配两个ID,所以我不知道如何构建它。
WHERE first_id = 'id1' AND second_id = 'id2'
我该如何使用Zend Framework实现这个功能?
通常,这个对我来说是有效的:
$db = Zend_Db_Table::getDefaultAdapter();
$where = $db->quoteInto('id = ?', $id);
$db->delete('tablename', $where);
但我需要匹配两个ID,所以我不知道如何构建它。
WHERE first_id = 'id1' AND second_id = 'id2'
我该如何使用Zend Framework实现这个功能?
在Jason W的回答基础上进行扩展:
不是很确定第三节在说什么。
这意味着你可以这样做:
$db->delete('tablename', array(
'first_id = ?' => $first_id,
'second_id = ?' => $second_id
));
适配器会为您引用所有内容。
不过,我觉得文档并不是很清楚。
从zend手册的delete()中:
如果省略第二个参数,则会删除表中所有行。
如果您将字符串数组作为第二个参数提供,则这些字符串将作为表达式中的术语连接起来,由AND运算符分隔。
如果您将数组数组作为第二个参数提供,则值将被自动引用到键中。然后,它们将作为术语连接在一起,由AND运算符分隔。
不确定第三部分在说什么,但第二部分意味着您可以进行以下操作:
$where = array();
$where[] = $db->quoteInto('first_id = ?', $first_id);
$where[] = $db->quoteInto('second_id = ?', $second_id);
$db->delete('tablename', $where);
class Yourmodel extends Zend_Db_Table_Abstract {
protected $_name = 'tablename';
protected $_primary = 'primarykey';
public function remove($first_id, $second_id) {
$where = array();
$where[] = $this->getAdapter()->quoteInto('first_id = ?', $first_id);
$where[] = $this->getAdapter()->quoteInto('second_id = ?', $second_id);
$this->delete($where);
}
}