I have the following Doctrine2 query:
$qb = $em->createQueryBuilder()
->select('t.tag_text, COUNT(*) as num_tags')
->from('CompanyWebsiteBundle:Tag2Post', 't2p')
->innerJoin('t2p.tags', 't')
->groupBy('t.tag_text')
;
$tags = $qb->getQuery()->getResult();
When run I get the following error:
[Semantical Error] line 0, col 21 near '*) as num_tags': Error: '*' is not defined.
How would I do MySQL count(*) in Doctrine2?
You should be able to do it just like this (building the query as a string):
$query = $em->createQuery('SELECT COUNT(u.id) FROM Entities\User u');
$count = $query->getSingleScalarResult();
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