有人知道如何在yii中使用andWhere()条件。我使用它时会出现以下错误。
CDbCommand and its behaviors do not have a method or closure named "andWhere".
这是示例代码
$result=Yii::app()->db->createCommand()
->select()
->from('{{product}}')
->andWhere('price>:param1', array(':param1'=>150))
->andWhere('price<:param2', array(':param2'=>210))
->queryAll();
答案 0 :(得分:6)
在{ii} 1.1.13中添加了andWhere()
功能。看来你使用的是yii的旧版本。更新框架
答案 1 :(得分:-1)
尝试这种方法怎么样,这是一个简单的豌豆
Yii::app()->db->createCommand()
->select("*")
->from('package')
->where('id=:id and status:status', array(':id'=>5,':status'=>1))
->queryRow();
甚至
$criteria = new CDbCriteria();
$criteria->condition = 'id=:id and status=:status';
$criteria->params = array(':id'=>$id,':status'=>1);
准确
$result=Yii::app()->db->createCommand()
->select()
->from('{{product}}')
->where('price>:param1 and price<:param2', array(':param1'=>150,':param2'=>210))
->queryAll();