With the code:
$qb = $entityManager->createQueryBuilder();
$qb->select('cat')->from('BuyAndSellSiteBundle:Category ', 'cat');
$qb->getQuery();
$a =$qb->getResult();
I get an exception:
FatalErrorException: Error: Call to undefined method Doctrine\ORM\QueryBuilder::getResult() in C:\xampp\htdocs\buySell\src\BuyAndSell\SiteBundle\Controller\DefaultController.php line
This makes sense. Because QueryBuilder
does not change itself, you need to store result of getQuery()
invocation :
$queryBuilder = $entityManager->createQueryBuilder();
$queryBuilder->select('cat')->from('BuyAndSellSiteBundle:Category ', 'cat');
// get the Query from the QueryBuilder here ...
$query = $qb->getQuery();
// ... then call getResult() on the Query (not on the QueryBuilder)
$result = $query->getResult();
Change to:
$a = $qb->getQuery()->getResult();
// or
$q = $qb->getQuery();
$a = $q->getResult();
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