gpt4 book ai didi

yii - 在 Yii 查询构建器中多次调用 where

转载 作者:行者123 更新时间:2023-12-05 00:33:49 31 4
gpt4 key购买 nike

我想使用多个调用构建查询,但在使用此代码时出现错误

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

但我有困难的条件和更简单的使用代码,如上层。

在 Codeigniter 中,我可以多次使用这些条件
$this->db->where()

最佳答案

你必须向它传递一个这样的数组:

$command->where(array('AND', 'value1 = :value1', 'value2 < :value2'), array(':value1' => 1, ':value2' => 2));

关于yii - 在 Yii 查询构建器中多次调用 where,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11562823/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com