【问题标题】:How to Use Multiple Conditions In An Update Statement With Zend_Db And QuoteInto如何在 Zend_Db 和 QuoteInto 的更新语句中使用多个条件
【发布时间】:2011-06-12 10:41:52
【问题描述】:

使用 Zend 框架,有没有办法使用 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);

参考文献

【问题讨论】:

    标签: zend-framework zend-db


    【解决方案1】:

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

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

    【讨论】:

    • 如果我有 OR 条件如何实现?
    【解决方案2】:

    从 1.8 开始,您可以使用:

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

    【讨论】:

    • 谢谢。我用$db->update($data, array('id = ?' => $id);
    • 希望这被记录下来 :-( 在 1.12.x 中仍然有效。
    【解决方案3】:

    只是刷新上面的答案

    $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);
    

    【讨论】:

      猜你喜欢
      • 2017-12-02
      • 2021-08-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-31
      • 2017-03-23
      相关资源
      最近更新 更多