How can I perform count(*)
operation using Symfony2 Doctrine ORM ?
Without knowing the Entity class name and fields.
I got query builder to my class and I want to perform count(*)
action.
I am doing the following:
public function count(QueryBuilder $queryBuilder)
{
$countQuery = clone queryBuilder;
$countQuery->select('count(*)');
$countQuery->setParameters(queryBuilder->getParameters());
return $countQuery->getQuery()->getSingleScalarResult();
}
This returns the following error: [Semantical Error] line 0, col 13 near '*) FROM Acme\DemoBundle\Entity\Product': Error: '*' is not defined.
DQL looks like this: SELECT count(*) FROM Acme\DemoBundle\Entity\Product Acme\DemoBundle\Entity\Product ORDER BY name desc, description asc
Any ideas? How to do it without specifying the column name ?