List of strings in prepared statement using Doctrine DBAL

Bram Gerritsen picture Bram Gerritsen · May 29, 2013 · Viewed 7.3k times · Source

Following the Doctrine DBAL documentation I should be able to bind a list of string values like this:

$sql = 'SELECT * FROM mytable WHERE myfield IN (?)';

$stmt = $conn->prepare($sql);
$stmt->bindValue('myfield', array('stringa', 'stringb', 'stringc'), \Doctrine\DBAL\Connection::PARAM_STR_ARRAY);

$stmt->execute();

This results in a PHP notice and kills my script.

Notice: Array to string conversion in C:\www\eurocampings\vendor\doctrine\dbal\lib\Doctrine\DBAL\Statement.php on line 142

Did I do something wrong?

Answer

xyfantis picture xyfantis · Jul 9, 2014

From Doctrine DBAL documentation:

The parameter list support only works with Doctrine\DBAL\Connection::executeQuery() and Doctrine\DBAL\Connection::executeUpdate(), NOT with the binding methods of a prepared statement.

It is on the end of this link: http://doctrine-dbal.readthedocs.org/en/latest/reference/data-retrieval-and-manipulation.html#list-of-parameters-conversion