How to Use Multiple Conditions In An Update Statement With Zend_Db And QuoteInto

本秂侑毒 提交于 2019-12-20 17:37:48

问题


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

  • http://blog.motane.lu/2009/05/21/zend_db-quoteinto-with-multiple-arguments/
  • http://codeaid.net/php/multiple-parameters-in-zend_db::quoteinto%28%29

回答1:


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



回答2:


Since 1.8 you can use:

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



回答3:


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


来源:https://stackoverflow.com/questions/6321504/how-to-use-multiple-conditions-in-an-update-statement-with-zend-db-and-quoteinto

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!