Yii Query Builder 多个 where 子句 [英] Yii Query Builder multiple where clauses
问题描述
我在我的堆栈中注意到我的查询没有被正确执行,因为我的查询构建器中有多个 where 子句.所以我看了这篇文章在Yii Query builder中多次调用
I noticed in my stack that my query wasn't being executed correctly as I had multiple where clauses in my querybuilder. So I looked at this post Multiple call where in Yii Query builder
应用了我读过的内容,但查询仍然没有结合 where 语句.我做错了什么?
Applied what i'd read, but still the query doesn't combine the where statements. What am I doing wrong?
$command = Yii::app()->db->createCommand()
....
->where(array('in', 'u.id', $licenses), array('and', 'i.date_added > DATE_SUB(u.date_expired, INTERVAL 30 DAY)'));
//->where(array('and', 'i.date_added > DATE_SUB(u.date_expired, INTERVAL 30 DAY)'));
//->where(array('and', 'u.date_expired > CURDATE()'))
->group('u.id');
这是 3 个单独的语句,但我在阅读时将它们组合在一起,但结果仍然相同.只有 1 个 where 子句.
These were 3 individual statements, but I combined them as I read, but still the same result. Only 1 where clause.
推荐答案
你应该使用 andWhere
方法.此方法放置 AND
关键字,因此您只需要条件:
You should use andWhere
method. This method is putting the AND
keyword so you juste need the condition:
$command = Yii::app()->db->createCommand()
....
->where(array('in', 'u.id', $licenses));
->andWhere('i.date_added > DATE_SUB(u.date_expired, INTERVAL 30 DAY)');
->andWhere('u.date_expired > CURDATE()')
->group('u.id');
这篇关于Yii Query Builder 多个 where 子句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!