Yii 1 查询 return 不正确的数据
Yii 1 query return incorrect data
我有疑问:
$listings = Yii::app()->db->createCommand('SELECT * FROM listings')->where(['or like','c_sales_stage',['Needs Refresh','Active']])->andWhere('c_listing_featured_c = 1')->queryAll();
Returns 所有列表,即使 c_listing_featured_c 为 0。
我做错了什么?
谢谢
正如 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();
我有疑问:
$listings = Yii::app()->db->createCommand('SELECT * FROM listings')->where(['or like','c_sales_stage',['Needs Refresh','Active']])->andWhere('c_listing_featured_c = 1')->queryAll();
Returns 所有列表,即使 c_listing_featured_c 为 0。 我做错了什么?
谢谢
正如 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();