Listening to SQL (Query Builder 17)
If you enable the debugging mode of the database, you can monitor any SQL operations executed by the database using the following methods:
Db::listen(function ($sql, $time, $explain, $master) { // 记录SQL echo $sql . ' [' . $time . 's] ' . ($master ? 'master' : 'slave'); // 查看性能分析结果 dump($explain); });
By default, if no monitoring operations are registered, these SQL execution will be logged according to different log types. Once SQL monitoring is set up, the SQL log needs to be taken over by itself.