Doctrine Query Builder 使用数组 [英] Doctrine Query Builder using Array

查看:21
本文介绍了Doctrine Query Builder 使用数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 id 数组:

I have an array of id:

Id_array; //array(2) { [0]=> int(9) [1]=> int(10) } 

我只想使用 Id_array 选择用户;当我没有数组而只有一个整数时,我设法做到了:

I simply want to select the users using Id_array; I managed to do this when I don't have an array but just an integer:

$query = $em->createQuery('SELECT u FROM Users u WHERE u.id = ?1');
$query->setParameter(1, 9); // I tested the value 9 here
$users = $query->getResult(); 

如何获取Id_array对应的所有用户?

How can I fetch all the users that correspond to Id_array?

推荐答案

或者不使用查询生成器:

Or without the query builder:

$query = $em->createQuery('SELECT u FROM Users u WHERE u.id IN (:id)');
$query->setParameter('id', array(1, 9));
$users = $query->getResult();

这篇关于Doctrine Query Builder 使用数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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