Created
April 22, 2015 11:49
-
-
Save junxy/cb7b8ea36f581ce40166 to your computer and use it in GitHub Desktop.
eloquent 5 sql log
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | |
| } | |
| ); |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ref: