J'ai cette requête SQL dans MySQLComment mettre une requête SQL dans QueryBuilder et éviter ``?
SELECT * FROM pt WHERE id=98 ORDER BY FIELD (position, 4, 3, 2, 1, 5)
et je dois faire une requête dans Yii2. Quand j'écris
'query' => Pt::find()->where(['id' => $model->id])
->OrderBy('FIELD (`position`, 4, 3, 2, 1, 5)')
Je reçois
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'LIMIT 20' at line 1
The SQL being executed was: SELECT * FROM `pt` WHERE `id`=98 ORDER BY FIELD (`position`, `4`, `3`, `2`, `1`, `5)` LIMIT 20
Comment éviter `` à la demande?
Essayez '-> OrderBy ('FIELD (position, 4, 3, 2, 1, 5)')' – RiggsFolly