Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Doctrine DBAL setParameter() with array value

I'm using doctrine DBAL and have some problem with SQL query as result of a queryBuilder.

$builder = $this->getConnection()->getQueryBuilder();
$builder->select(['id','name','type'])
         ->from('table')
         ->where('id='.(int)$value)
         ->setMaxResults(1);
$builder->andWhere($builder->expr()->in('type', ['first','second']));

echo(builder->getSQL());

$data = $builder->execute()->fetchRow();

And get SQL

SELECT id, name, type FROM table WHERE (id=149) AND (type IN (first,second)) LIMIT 1

And this is the problem, I need that (type IN (first,second)) was encoded as strings like (type IN ('first','second'))

How to do that with query builder in the right way?

like image 524
Sergey Nikolaev Avatar asked Jul 06 '15 10:07

Sergey Nikolaev


1 Answers

Try with

$builder->andWhere('type IN (:string)');
$builder->setParameter('string', array('first','second'), \Doctrine\DBAL\Connection::PARAM_STR_ARRAY);
like image 114
DonCallisto Avatar answered Oct 10 '22 08:10

DonCallisto