我有查询:
$listings = Yii::app()->db->createCommand('SELECT * FROM listings')->where(['or like','c_sales_stage',['Needs Refresh','Active']])->andWhere('c_listing_featured_c = 1')->queryAll();
返回所有列表,即使c_listing_featured_c为 0。我做错了什么?
谢谢
正如文档所说:
注: 查询生成器不能用于修改指定为 SQL 语句的现有查询。例如,以下代码将不起作用:
$command = Yii::app()->db->createCommand('SELECT * FROM tbl_user');
// the following line will NOT append WHERE clause to the above SQL
$command->where('id=:id', array(':id'=>$id));
要解决您的问题createCommand()
请从函数中删除参数并在链中添加from()
:
$listings = Yii::app()->db->createCommand()
->from('listings')
//->where() //here your where condition
->andWhere('c_listing_featured_c = 1')
->queryAll();