laravel sql打印

2019-03-23sad creeper

1、

DB::listen(function($query) {
$bindings = $query->bindings;
$sql = $query->sql;
foreach ($bindings as $replace){
$value = is_numeric($replace) ? $replace : "'".$replace."'";
$sql = preg_replace('/\?/', $value, $sql, 1);
}
dd($sql);
});

sql语句

(laravel SQL打印比较麻烦)

2、

下面这个会记录到日志里面去,不会影响程序的运行

DB::listen(function($query) {
$bindings = $query->bindings;
$sql = $query->sql;
foreach ($bindings as $replace){
$value = is_numeric($replace) ? $replace : "'".$replace."'";
$sql = preg_replace('/\?/', $value, $sql, 1);
}
logger($sql);
});

3、

DB::enableQueryLog();

dd(DB::getQueryLog());

其他更多请查看一下连接:

https://learnku.com/laravel/wikis/27707

阅读 769 评论