Option 1
and Option 2
seem to give similar results. Is there a particular advantage for using the execute statement
rather than the usual getResult()
method?
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
));
}
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();
}
Basically getResult()
is alias for execute(array())
you can set as argument hydration mode for example: getResult(Query::HYDRATE_OBJECT)
is execute(array(), Query::HYDRTE_OBJECT)
Only difference: in execute method you can set query parameters as first argument so you do not have to call setParameter
method before...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With