How to use andWhere in Yii [duplicate]

2019-09-10 02:15发布

This question already has an answer here:

Does anybody know how to use the andWhere() condition in yii. I'm getting the below error when i use it.

CDbCommand and its behaviors do not have a method or closure named "andWhere". 

here is sample code

 $result=Yii::app()->db->createCommand()
->select()
->from('{{product}}')
->andWhere('price>:param1', array(':param1'=>150))
->andWhere('price<:param2', array(':param2'=>210))
->queryAll();

标签: php yii
2条回答
Fickle 薄情
2楼-- · 2019-09-10 02:41

The andWhere() function is added in yii 1.1.13. It seems you are using older version of yii. Update the framework

查看更多
贪生不怕死
3楼-- · 2019-09-10 02:43

how about trying this method , it's a easy peazy

Yii::app()->db->createCommand()
       ->select("*")
       ->from('package')
       ->where('id=:id and status:status', array(':id'=>5,':status'=>1))
       ->queryRow();

or even

    $criteria = new CDbCriteria();
    $criteria->condition = 'id=:id and status=:status';
    $criteria->params = array(':id'=>$id,':status'=>1);

to be exact

$result=Yii::app()->db->createCommand()
   ->select()
   ->from('{{product}}')
   ->where('price>:param1 and price<:param2', array(':param1'=>150,':param2'=>210))
   ->queryAll();
查看更多
登录 后发表回答