Skip to content

Instantly share code, notes, and snippets.

@jpadilla
Created April 2, 2012 12:35
Show Gist options
  • Save jpadilla/2283142 to your computer and use it in GitHub Desktop.
Save jpadilla/2283142 to your computer and use it in GitHub Desktop.
Doctrine 2 Logger for CodeIgniter's Profiler
<?php
namespace Doctrine\DBAL\Logging;
class Profiler implements SQLLogger
{
public $start = null;
private $ci;
public function __construct()
{
$this->ci =& get_instance();
}
/**
* {@inheritdoc}
*/
public function startQuery($sql, array $params = null, array $types = null)
{
$this->start = microtime(true);
$this->ci->db->queries[] = "/* doctrine */ \n".$sql;
}
/**
* {@inheritdoc}
*/
public function stopQuery()
{
$this->ci->db->query_times[] = microtime(true) - $this->start;
}
}
@colonelchlorine
Copy link

Smart cookie. Maybe do this instead on startQuery so that you can get the query parameters shown instead of question marks

$this->start = microtime(true);
$params_copy = $params;
$this->ci->db->queries[] = "/* Doctrine */ \n" . preg_replace_callback('/\?/', function($match) use(&$params_copy)
   {
      return array_shift($params_copy);
   }, $sql);
unset($params_copy);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment