我正在使用doctrine DBAL,并且由于queryBuilder而导致SQL查询出现问题.
$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();
并获得sql
SELECT id,name,type FROM table WHERE (id=149) AND (type IN (first,second)) LIMIT 1
这就是问题,我需要(输入IN(第一,第二))被编码为字符串(类型IN(‘first’,’second’))
如何以正确的方式使用查询构建器?
试试吧
原文链接:https://www.f2er.com/php/133085.html$builder->andWhere('type IN (:string)'); $builder->setParameter('string',array('first','second'),\Doctrine\DBAL\Connection::PARAM_STR_ARRAY);