This question already has an answer here:
-
Yii CDbCommand create query
1 answer
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();
The andWhere()
function is added in yii 1.1.13. It seems you are using older version of yii. Update the framework
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();