Doctrine 2 DQL IN statement
I have been working with Doctrine 2 for the last month. This week, I really needed to pass an array of values to the Doctrine 2′s DQL IN statement. There is no documentation on Doctrine’s web site for passing in an array of identifiers. Here is how to pass in an array of identifiers into DQL
For Integers
$em->createQuery("SELECT users FROM Entities\User users WHERE users.id IN(".implode(' ',$userIds).")");
For Strings
$em->createQuery("SELECT users FROM Entities\User users WHERE users.id ('".implode("', '", $userUuids)."')");
The Query object does not support flattening arrays and throws the exception, “Doctrine\ORM\Query\QueryException: Invalid parameter number: number of bound variables does not match number of tokens”
Advertisement
Did you find the solution?
http://www.doctrine-project.org/projects/orm/1.2/docs/manual/dql-doctrine-query-language/hu#conditional-expressions:in-expressions
That solution is for Doctrine 1.2, not for Doctrine 2.0.