How to Use Multiple Conditions In An Update Statem

2020-06-02 00:32发布

Using Zend Framework, is there a way to pass multiple conditions to an update statement using the quoteInto method? I've found some references to this problem but I'm looking for a supported way without having to extend Zend_Db or without concatenation.

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

References

3条回答
Evening l夕情丶
2楼-- · 2020-06-02 00:40

You can use an array type for your $where argument. The elements will be combined with the AND operator:

$where = array();
$where[] = $this->getAdapter()->quoteInto('user_id = ?', $form['id']);
$where[] = $this->getAdapter()->quoteInto('key = ?', $key);
$this->update(array('value' => $form['value']), $where);
查看更多
smile是对你的礼貌
3楼-- · 2020-06-02 00:47

Just refreshing the above answer

$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);
查看更多
在下西门庆
4楼-- · 2020-06-02 00:58

Since 1.8 you can use:

$where = array(
    'name = ?' => $name,
    'surname = ?' => $surname
);
$db->update($data, $where);
查看更多
登录 后发表回答