在 Yii 查询构建器中多次调用 where [英] Multiple call where in Yii Query builder
本文介绍了在 Yii 查询构建器中多次调用 where的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想通过多次调用构建查询,但在使用此代码时出现错误
I want to build query with multiple call where, but i have error, when use this code
$command = Yii::app()->db->createCommand()
->select('*')
->from('{{table}}');
$command->where('value1 = :value1', array(':value1' => 1));
$command->where('value2 < :value2', array(':value2' => 2));
我明白,我可以使用像
$command->where('value1 = :value1 AND value2 = :value2', array(':value1' => 1, ':value2' => 2));
但我有困难的条件和更简单的使用代码,如上层.
but i have difficult conditions and simpler its use code like upper.
在 Codeigniter 中,我可以多次使用这些条件
In Codeigniter i can use those condition several times
$this->db->where()
推荐答案
你必须像这样传递一个数组:
You have to pass it an array like this:
$command->where(array('AND', 'value1 = :value1', 'value2 < :value2'), array(':value1' => 1, ':value2' => 2));
这篇关于在 Yii 查询构建器中多次调用 where的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文