Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony2 & Doctrine - Get number of rows returned from datasource

I have the following code in my Symfony2 Repository Class...

$query = $this->createQueryBuilder('foo')         ->where('foo.bar = :id')         ->setParameter('id', $myID)         ->getQuery(); 

How do I get the number of rows found by the database?

Thanks in advance

like image 308
Matt Avatar asked Nov 22 '11 12:11

Matt


People also ask

Which is better Symfony or Laravel?

Laravel is preferred by developers for its fast development, performance, and high speed. Whereas, Symfony is suitable for the development of complex and large-size web applications effortlessly. We've done a full analysis of the features of each framework's capabilities, as well as its pros and cons.

What is Symfony used for?

Symfony is a feature-rich back-end framework that is used to build complex applications. Many developers still prefer the lightweight Silex micro-framework or the Symfony MicroKernel, and Symfony is a widely used application framework among open-source developers.

What is Symphony language?

Symfony is an open-source PHP web application framework, designed for developers who need a simple and elegant toolkit to create full-featured web applications.

Who created Symfony?

Ask me anything! Hi all, I created Symfony in 2005, one of the most popular PHP frameworks.


1 Answers

You need to execute DQL to do something you want.

$query = $this->createQueryBuilder()               ->from('foo', 'f')               ->where('foo.bar = :id')               ->setParameter('id', $myID)               ->getQuery();   $total = $query->select('COUNT(f)')                ->getQuery()                ->getSingleScalarResult(); 
like image 173
Reuven Avatar answered Sep 23 '22 19:09

Reuven