我尝试执行以下查询
$em->createQuery('select i from AcmePublicBundle:Public i where i.user in (:opc)');
$query->setParameter('opc', $opc);
where :opc is an array like this
$opc={array}[2]
0 = {array}[1]
id = "9"
1 = {array}[1]
id = "10" 我得到了这个错误
Notice: Undefined offset: 0 in...如果我尝试这样做
$em->createQuery('select i from AcmePublicBundle:Public i where i.usuario in (9, 10)');百事大吉。但我必须通过$opc。
有什么想法吗?
发布于 2012-10-19 17:17:20
是的,错误似乎很合适,因为setParameter同时考虑了array键和值,而键代表字段名。因此,您不能在这里使用矩阵。
$ids = array();
foreach ( $opc as $o ){
$ids[] = (int)$o[1]; //be careful about data type (string, int etc)
}
$q = " .... WHERE id IN (:opc) ... ";
$q->setParameter('opc', $ids);这应该行得通..。
发布于 2012-10-19 17:17:28
您的$opc数组不应是多维的。尝试像这样传递一个数组:
$opc=array(
'9',
'10'
);而不是
$opc=array(
array('id'=>'9'),
array('id'=>'10')
);https://stackoverflow.com/questions/12970584
复制相似问题