简体   繁体   English

Symfony2学说mysql IN查询

[英]Symfony2 doctrine mysql IN query

I have array of products IDs. 我有一组产品ID。 I have to make query like this: 我必须这样查询:

SELECT * FROM products WHERE pid IN (1, 2, 8, 4, ...) // etc

I have my ids in variable $pids. 我的变量$ pids中有我的ID。

$qb = $em->createQueryBuilder();
$query = $qb->select('p.pid')
            ->from('SRC\MainBundle\Entity\Product', 'p')
            ->where('p.name IN :pids') // error is HERE
            ->setParameter('pids', $pids)
            ->getQuery();

Doesn't work. 不起作用 I get an error: 我收到一个错误:

[Syntax Error] line 0, col 66: Error: Expected Doctrine\ORM\Query\Lexer::T_OPEN_PARENTHESIS, got ':pids'

What if you try 如果您尝试怎么办

->where('p.name IN (:pids)') // error is HERE

It explicitly says to you that it expects parentheses but gets placeholder 它明确地告诉您,它需要parentheses但会placeholder

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM