yii1查询返回错误数据

gwo2fgha  于 2021-06-21  发布在  Mysql
关注(0)|答案(1)|浏览(436)

我有疑问:

$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\u listing\u featured\u c为0。我做错什么了?
谢谢

6bc51xsx

6bc51xsx1#

正如文件所说:
注意:查询生成器不能用于修改指定为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();

相关问题