Skip to content

Instantly share code, notes, and snippets.

@junxy
Created April 22, 2015 11:49
Show Gist options
  • Select an option

  • Save junxy/cb7b8ea36f581ce40166 to your computer and use it in GitHub Desktop.

Select an option

Save junxy/cb7b8ea36f581ce40166 to your computer and use it in GitHub Desktop.
eloquent 5 sql log
use Illuminate\Database\Capsule\Manager as DB;
DB::enableQueryLog();
DB::listen(
function ($sql, $bindings, $time) {
// $sql - select * from `ncv_users` where `ncv_users`.`id` = ? limit 1
// $bindings - [5]
// $time(in milliseconds) - 0.38
// Uncomment this if you want to include bindings to queries
$sql = str_replace(array('%', '?'), array('%%', '%s'), $sql);
$sql = vsprintf($sql, $bindings);
$time_now = (new DateTime)->format('Y-m-d H:i:s');;
$log = $time_now . ' | ' . $sql . ' | ' . $time . 'ms' . PHP_EOL;
echo $log;
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment