Answer the question
In order to leave comments, you need to log in
Why does Yii2 SQL query execute, but not via ActiveRecord?
Hello.
Why does query 1 execute and 2 return an empty set?
Request 1:
Yii::$app->db->createCommand('SELECT MONTH(reg_date) AS Months, COUNT(*) AS RegCount FROM users WHERE YEAR(reg_date) = YEAR(NOW()) ORDER BY Months')->queryAll();
$this->find()->select(['MONTH(reg_date) AS Months', 'COUNT(*) AS RegCount'])->where(['YEAR(reg_date)' => 'YEAR(NOW())'])->groupBy('Months')->all();
Answer the question
In order to leave comments, you need to log in
I think it's about escaping when parsing select, try doing it through yii\db\Expression:
https://www.yiiframework.com/doc/api/2.0/yii-db-ex...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question