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

3 comments so far

  1. Bas on

    Did you find the solution?

    • redbeardtechnologies on

      That solution is for Doctrine 1.2, not for Doctrine 2.0.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.