How can i get count of queries to database in Doctrine2? I need this just for statistic and to find out more how doctrine work, how much queries generated in different situations. But anyway, how to do this?
2 Answers
Just to add to accepted answer.
To do this from the context of Symfony 2.x controller:
$doctrine = $this->get('doctrine');
$doctrine = $this->getDoctrine();
$em = $doctrine->getConnection();
// $doctrine->getManager() did not work for me
// (resulted in $stack->queries being empty array)
$stack = new \Doctrine\DBAL\Logging\DebugStack();
$em->getConfiguration()->setSQLLogger($stack);
... // do some queries
var_dump($stack->queries);
Thanks to this post: http://vvv.tobiassjosten.net/symfony/logging-doctrine-queries-in-symfony2/
1 Comment
A.L
$doctrine->getManger() did not work for me Is it because of the missing a?