我有以下代码给出以下异常,我不知道为什么,任何帮助将不胜感激。
无效的参数号:绑定变量的数量与标记的数量不匹配
if (!empty($ids)) {
$queryIds = implode(",", $ids);
$query = $em->createQueryBuilder()
->from('MainClientBundle:Posts','p')
->select('p')
->where('p.id >= :rand')
->where('p.id NOT IN (:ids)')
->orderBy('p.id','ASC')
->setParameter('rand', rand(1, $max))
->setParameter('ids', $queryIds)
->setMaxResults(1);
} else {
$query = $em->createQueryBuilder()
->from('MainClientBundle:Posts','p')
->select('p')
->where('p.id >= :rand')
->orderBy('p.id','ASC')
->setParameter('rand', rand(1, $max))
->setMaxResults(1);
}
try {
if($options['videos'] == "off"){
$query->where("p.type <> :type")->setParameter("type",1);
}
if($options['sfw'] == "on"){
$query->where("p.safeForWork <> :sfw")->setParameter("sfw",0);
}
$post = $query->getQuery()->getSingleResult();
} catch (\Doctrine\Orm\NoResultException $e) {
$post = null;
}