在Doctrine 2.0中如何使用DQL中的in语句 [英] How to use the in statement in DQL in Doctrine 2.0

查看:358
本文介绍了在Doctrine 2.0中如何使用DQL中的in语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下使用IN语句的查询。

I have the following query that uses an IN statement.

$ids = array(1,2,3);
$query = 'select o from Organisation o where o.id in (:ids)';
$this->_entityManager->createQuery($query)
            ->setParameter('ids', implode(', ', $ids))

教义没有返回任何结果,我认为这是因为Doctrine对传递的参数 $ ids 这是一个数组。

Doctrine is not returning any results, I think it is because of something wrong in the conversion that Doctrine does for the passed parameter $ids which is an array.

如何使其工作?

推荐答案

尝试传递数组本身到 - > setParameter(...)而不是将其转换成字符串。

Try passing the array itself to ->setParameter(...) instead of imploding it into a string.

这篇关于在Doctrine 2.0中如何使用DQL中的in语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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