1.记录所有sql查询记录
app/Providers/EventServiceProvider.php
public function boot() { parent::boot(); \DB::listen(function ($query) { $tmp = str_replace('?', '"'.'%s'.'"', $query->sql); $qBindings = []; foreach ($query->bindings as $key => $value) { if (is_numeric($key)) { $qBindings[] = $value; } else { $tmp = str_replace(':'.$key, '"'.$value.'"', $tmp); } } $tmp = vsprintf($tmp, $qBindings); $tmp = str_replace("\\", "", $tmp); \Log::info(' execution time: '.$query->time.'ms; '.$tmp."\n\t"); } ); }
本文为看恩吧原创文章,转载无需和我联系,但请注明来自knsay.com