16

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

ezraspectre
  • 3,148
  • 5
  • 23
  • 28

3 Answers3

24

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);
Mark Elliot
  • 75,278
  • 22
  • 140
  • 160
Aron Rotteveel
  • 81,193
  • 17
  • 104
  • 128
16

Since 1.8 you can use:

$where = array(
    'name = ?' => $name,
    'surname = ?' => $surname
);
$db->update($data, $where);
Tomáš Fejfar
  • 11,129
  • 8
  • 54
  • 82
-2

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);
EaterOfCode
  • 2,202
  • 3
  • 20
  • 33
besin
  • 106
  • 4