Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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
like image 636
ezraspectre Avatar asked Jun 12 '11 10:06

ezraspectre


1 Answers

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);
like image 95
Aron Rotteveel Avatar answered Sep 22 '22 08:09

Aron Rotteveel