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

ezr*_*tre 16 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);
Run Code Online (Sandbox Code Playgroud)

参考

Aro*_*eel 22

您可以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);
Run Code Online (Sandbox Code Playgroud)


Tom*_*far 16

从1.8开始你可以使用:

$where = array(
    'name = ?' => $name,
    'surname = ?' => $surname
);
$db->update($data, $where);
Run Code Online (Sandbox Code Playgroud)

  • 希望这是记录:-(仍然有效在1.12.x. (2认同)