Doctrine DBAL - WHERE IN array with additional parameter

The params and types are parallel arrays. All you should have to do is add your placeholder for the f.foo value and add in the correct PDO type in types argument.

$SQL = "SELECT f.foo, b.bar
        FROM Foo f LEFT JOIN Bar b
        WHERE  f.foo = ? AND b.bar IN (?)";

$result = $this->connection
    ->executeQuery($SQL, array($foo, $bar_array),array(
            \PDO::PARAM_INT,
            \Doctrine\DBAL\Connection::PARAM_INT_ARRAY
     ))->fetchAll();

You can read the manual for more information.


I just encountered the below behavior, so I am writing it here, maybe it will prove useful for someone else.

Beware when using named parameters with IN. You will have to repeat the names for the type-array as well:

$sql = "SELECT * FROM myTable WHERE name IN (:param_array)";

$stmt = $this->db->executeQuery(
        $sql,
        [
            'param_array' => $paramArray
        ],
        [
            'param_array' => Connection::PARAM_STR_ARRAY
        ]
    );