Symfony2 学说 mysql IN 查询 [英] Symfony2 doctrine mysql IN query

查看:32
本文介绍了Symfony2 学说 mysql IN 查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一系列产品 ID.我必须像这样进行查询:

I have array of products IDs. I have to make query like this:

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

我的 ID 在变量 $pids 中.

I have my ids in variable $pids.

$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'

推荐答案

如果您尝试会怎样

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

它明确告诉你它需要 括号 但得到 placeholder

It explicitly says to you that it expects parentheses but gets placeholder

这篇关于Symfony2 学说 mysql IN 查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆