I need to specify bind paramaters in my CDbCriteria object, the only problem I’m having is that conditions are only added if they exist in the GET, for example:
If one of the GET variables is empty then the query fails because "number of bound variables does not match number of tokens".
How can I resolve this issue?
Secondly, when I try to use an addInCondition() alongside a normal condition I get an error about bind variables, even though I’m just specifying the value directly, eg:
Cheers Antonio. $_GET[‘genre’] is already an array so I don’t think it needs to be entered as an array. I confirmed this because I get an “array to string conversion” error when I enclose it in an array.
Anyway it is still complaining that the number of bind variables do not match.
I checked the generated SQL and this is what I get:
WHERE ((gender=:gender) AND (genre IN (:ycp0, :ycp1))). Bound with :gender=‘2’
It seems that the ‘genre’ bind variables are not getting generated.
This only occurs when the $_GET[‘gender’] variable is present.
EDIT: I think I found out what the problem was. Basically the bind params have to be added to $criteria->params like this:
I never had this problem as I use sub-queries on addInConditions. I wonder if IN statements are supported differently on the new CDbCommand as suggested by qiang. Didn’t have a deep look at its code yet.
Congrats anyway, I will note this as a hint for future challenges.