【问题标题】:Yii 1 query return incorrect dataYii 1 查询返回不正确的数据
【发布时间】:2018-01-08 12:23:39
【问题描述】:

我有疑问:

$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 查询。

标签: php mysql database yii yii1.x


【解决方案1】:

正如documentation 所说:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多