Laravel5打印所有运行SQL
时间:2021-07-01 10:21:17
帮助过:4人阅读
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();
Laravel5打印所有运行SQL
标签:div mamicode query inf 图片 bind ati lis stat