Как использовать несколько условий в обновлении с помощью Zend_Db и QuoteInto
Использование Zend Framework, есть ли способ передать несколько условий в оператор обновления с помощью метода quoteInto? Я нашел некоторые ссылки на эту проблему, но я ищу поддерживаемый способ без расширения Zend_Db или без конкатенации.
$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);
Ссылки
Ответы
Ответ 1
Вы можете использовать тип array
для вашего аргумента $where
. Элементы будут объединены с оператором AND
:
$where = array();
$where[] = $this->getAdapter()->quoteInto('user_id = ?', $form['id']);
$where[] = $this->getAdapter()->quoteInto('key = ?', $key);
$this->update(array('value' => $form['value']), $where);
Ответ 2
Начиная с версии 1.8 вы можете использовать:
$where = array(
'name = ?' => $name,
'surname = ?' => $surname
);
$db->update($data, $where);
Ответ 3
Просто обновляя приведенный выше ответ
$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);