added query event for hooking into database for logging.

This commit is contained in:
Taylor Otwell 2012-02-01 08:25:54 -06:00
parent 96b43e90b3
commit 982e009a96
1 changed files with 17 additions and 2 deletions

View File

@ -1,4 +1,4 @@
<?php namespace Laravel\Database; use PDO, PDOStatement; <?php namespace Laravel\Database; use PDO, PDOStatement, Laravel\Event;
class Connection { class Connection {
@ -222,7 +222,7 @@ protected function execute($sql, $bindings = array())
// execution time in a static array that is accessed by all of // execution time in a static array that is accessed by all of
// the connections used by the application. This allows us to // the connections used by the application. This allows us to
// review all of the executed SQL. // review all of the executed SQL.
static::$queries[] = compact('sql', 'bindings', 'time'); static::log($sql, $bindings, $time);
return array($statement, $result); return array($statement, $result);
} }
@ -260,6 +260,21 @@ protected function transform($sql, $bindings)
return trim($sql); return trim($sql);
} }
/**
* Log the query and fire the core query event.
*
* @param string $sql
* @param array $bindings
* @param int $time
* @return void
*/
protected static function log($sql, $bindings, $time)
{
Event::fire('laravel: query', array($sql, $bindings, $time));
static::$queries = compact('sql', 'bindings', 'time');
}
/** /**
* Get the driver name for the database connection. * Get the driver name for the database connection.
* *