如何在Zend_Db和QuoteInto的更新语句中使用多个条件

时间:2011-06-12 10:41:53

标签: zend-framework zend-db

使用Zend Framework,有没有办法使用quoteInto方法将多个条件传递给更新语句?我发现了一些对这个问题的引用,但我正在寻找一种支持的方式,而不必扩展Zend_Db或没有连接。

$db = $this->getAdapter();
$data = array('profile_value' => $form['profile_value']);
$where = $db->quoteInto('user_id = ?', $form['id'])
       . $db->quoteInto(' AND profile_key = ?', $key);         
$this->update($data, $where);

参考

3 个答案:

答案 0 :(得分:21)

您可以为array参数使用$where类型。元素将与AND运算符结合使用:

$where = array();
$where[] = $this->getAdapter()->quoteInto('user_id = ?', $form['id']);
$where[] = $this->getAdapter()->quoteInto('key = ?', $key);
$this->update(array('value' => $form['value']), $where);

答案 1 :(得分:15)

从1.8开始,您可以使用:

$where = array(
    'name = ?' => $name,
    'surname = ?' => $surname
);
$db->update($data, $where);

答案 2 :(得分:-2)

刷新上述答案

$data = array('value' => $form['value']);
$where = array();
$where[] = $this->getAdapter()->quoteInto('user_id = ?', $form['id']);   
$where[] = $this->getAdapter()->quoteInto('key = ?', $key);
$this->update($data, $where);