Laravel5打印所有运行SQL
作者:互联网
//function //laravel 官方打印sql public static function printAllSql(){ DB::listen(function($query) { $sql_arr = []; $bindings = $query->bindings; $sql = $query->sql; foreach ($bindings as $replace){ $value = is_numeric($replace) ? $replace : "'".$replace."'"; $sql = preg_replace('/\?/', $value, $sql, 1); } $sql_arr[] = $sql; print_r($sql_arr); }); }
//调用方式:直接在请求流的最上面调用方法即可
printAllSql();
标签:function,arr,SQL,Laravel5,打印,replace,sql,query,bindings 来源: https://blog.51cto.com/u_15230485/2821444