Pregunta

I have build my own mvc framework and i'm using Doctrine DBAL 2.3 as database layer. At the moment i'm working on a profiler for this framework. One of the things i want to put in the profiler is the number of querys that were executed on the current page.

My question is: can i get the number of querys from Doctrine? Yes? How can i do this? No? Is there a way to build something custom that works with Doctrine and does the trick?

I hope there is someone that can answer my question, thank you.

¿Fue útil?

Solución

Doctrine 2 provides a simple interface for logging, namely \Doctrine\DBAL\Logging\SQLLogger()

https://github.com/doctrine/dbal/blob/master/lib/Doctrine/DBAL/Logging/SQLLogger.php

$config = new Doctrine\ORM\Configuration ();
// ... config stuff
$config->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger());
$connectionParams = array(
        'dbname' => 'example',
        'user' => 'example',
        'password' => 'example',
        'host' => 'localhost',
        'driver' => 'pdo_mysql');
//make the connection through an Array of params ($connectionParams)
$em = EntityManager::create($connectionParams, $config);
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top