如何在 Zend_Db 和 QuoteInto 的更新语句中使用多个条件 [英] How to Use Multiple Conditions In An Update Statement With Zend_Db And QuoteInto

查看:36
本文介绍了如何在 Zend_Db 和 QuoteInto 的更新语句中使用多个条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 Zend 框架,有没有办法使用 quoteInto 方法将多个条件传递给更新语句?我找到了一些对此问题的参考,但我正在寻找一种无需扩展 Zend_Db 或无需连接即可支持的方法.

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

参考资料

推荐答案

您可以将 array 类型用于 $where 参数.元素将与 AND 运算符组合:

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

这篇关于如何在 Zend_Db 和 QuoteInto 的更新语句中使用多个条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆