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

3

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

Tribune answered 12/6, 2011 at 10:41 Comment(0)
O
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);
Outsize answered 12/6, 2011 at 10:57 Comment(1)
how to achieve this if I have OR condition?Adama
B
16

Since 1.8 you can use:

$where = array(
    'name = ?' => $name,
    'surname = ?' => $surname
);
$db->update($data, $where);
Beggary answered 14/5, 2012 at 15:56 Comment(2)
Thanks for this. I used $db->update($data, array('id = ?' => $id);Fichte
Wish this was documented :-( Still valid in 1.12.x.Sufficient
A
-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);
Avertin answered 9/5, 2012 at 7:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.