Laravel 4 SQL log / console

后端 未结 8 2219
感动是毒
感动是毒 2020-12-31 05:50

Is there something similar in Laravel that allows you to see the actual SQL being executed? In Rails, for example, you can see the SQL in console. In Django you have a tool

8条回答
  •  青春惊慌失措
    2020-12-31 06:05

    I came up with a really simple way (if you are using php artisan serve and PHP 5.4) - add this to app/start/local.php:

    DB::listen(function($sql, $bindings, $time)
    {
        file_put_contents('php://stderr', "[SQL] {$sql} in {$time} s\n" . 
                          "      bindinds: ".json_encode($bindings)."\n");
    });
    

    but hoping to find a more official solution.

    This will print SQL statements like this:

    [SQL] select 1 in 0.06s
    

提交回复
热议问题