Option 1
并且Option 2
似乎给出了类似的结果。使用execute statement
而不是通常的getResult()
方法有什么特别的优势吗?
选项1:
public function getEventsByOrganiser(EventInterface $event, $username)
{
$qb = $this->repository->createQueryBuilder('e')
->select(array('e', 'u'))
->leftJoin('e.user', 'u')
->andWhere('u.username = :username');
return $qb->getQuery()->execute(array(
'username' => $username
));
}
选项2:
public function getEventsByOrganiser(EventInterface $event, $username)
{
$qb = $this->repository->createQueryBuilder('e')
->select(array('e', 'u'))
->leftJoin('e.user', 'u')
->andWhere('u.username = :username')
->setParameter('username', $username);
return $qb->getQuery()->getResult();
}