Skip to content

Instantly share code, notes, and snippets.

@o
Created March 1, 2012 01:11
Show Gist options
  • Save o/1946396 to your computer and use it in GitHub Desktop.
Save o/1946396 to your computer and use it in GitHub Desktop.
Doctrine 2 Query Profiler
<?php
class Profiler implements Doctrine\DBAL\Logging\SQLLogger {
private $start;
private $sql;
private $params;
private $types;
public function startQuery($sql, array $params = null, array $types = null) {
$this->sql = $sql;
$this->start = microtime(true);
$this->params = $params;
$this->types = $types;
}
public function stopQuery() {
var_dump(
array(
'sql' => $this->sql,
'query_time' => microtime(true) - $this->start,
'params' => $this->params,
'types' => $this->types
)
);
}
}
/**
array
'sql' => 'SELECT t0_.id AS id0, t0_.title AS title1, t0_.created_at AS created_at2, t0_.comments_enabled AS comments_enabled3...'
'query_time' => 0.37213706970215
'params' =>
array
empty
'types' =>
array
empty
**/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment