jdelight
(Mrjamesdacosta)
1
If you try to do something like this:
User::model()->findAllBySql("… AND UserType IN :userTypes…", array(’:userTypes’=>"(1,2,3)"));
You get an error because the binding puts quotes arround the brackets: e.g.
AND UserType IN "(1,2,3)"
instead of
AND UserType IN (1,2,3)
Any way to get round this?
qiang
(Qiang Xue)
2
You can’t bind this way. It is not supported by PDO. You have to bind one by one.
You may also consider using: $db->commandBuilder->createInCondition()
jdelight
(Mrjamesdacosta)
3
Seems to work if you move the parentheses outside the value being bound.
I.e instead of
User::model()->findAllBySql("… AND UserType IN :userTypes…", array(’:userTypes’=>"(1,2,3)"));
THIS DOES WORK
User::model()->findAllBySql("… AND UserType IN (:userTypes)…", array(’:userTypes’=>“1,2,3”));
jdelight
(Mrjamesdacosta)
4
Actually this doesn’t work - you need Yii::app()->db->schema->commandBuilder->createInCondition()