Sql Logger in dev

This commit is contained in:
Michael RICOIS 2016-10-18 14:55:24 +02:00
parent 9863ace419
commit f3c067614a
2 changed files with 53 additions and 0 deletions

View File

@ -146,7 +146,14 @@ class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
protected function _initDoctrine()
{
$c = new Zend_Config($this->getOptions());
$config = new \Doctrine\DBAL\Configuration();
if (APPLICATION_ENV == 'development') {
$logger = new Scores_Logger_Sql();
$config->setSQLLogger($logger);
}
$connectionParams = array(
'dbname' => $c->profil->db->metier->params->dbname,
'user' => $c->profil->db->metier->params->username,

View File

@ -0,0 +1,46 @@
<?php
use Doctrine\DBAL\Logging\SQLLogger;
class Scores_Logger_Sql implements SQLLogger
{
/**
* Executed SQL queries.
*
* @var array
*/
public $query = array();
/**
* If Debug Stack is enabled (log queries) or not.
*
* @var boolean
*/
public $enabled = true;
/**
* @var float|null
*/
public $start = null;
/**
* {@inheritdoc}
*/
public function startQuery($sql, array $params = null, array $types = null)
{
if ($this->enabled) {
$this->start = microtime(true);
$this->query = array('sql' => $sql, 'params' => $params, 'types' => $types, 'executionMS' => 0);
}
}
/**
* {@inheritdoc}
*/
public function stopQuery()
{
if ($this->enabled) {
$this->query['executionMS'] = microtime(true) - $this->start;
file_put_contents('logger.log', print_r($this->query,1), FILE_APPEND);
}
}
}