Blogger Information
Blog 7
fans 0
comment 0
visits 15451
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
Laravle(DB::listen) (数据库监听)
冷雨画桥
Original
2292 people have browsed it

Laravel-数据库监听

  1. <?php
  2. namespace App\Providers;
  3. class AppServiceProvider extends ServiceProvider
  4. {
  5. public function boot(){
  6. DB::listen(function($query){
  7. //剔除命令行sql
  8. if(app()->runningInConsole()) return;
  9. $request = request();
  10. //防止重复录入形成死循环 sql_log有关的表不显示
  11. if(strpos($query->sql,'sql_log' !=false)) return;
  12. $sqlLog = [
  13. 'sql' => vsprintf(str_replace("?", "'%s'", $query->sql), $query->bindings),
  14. 'time' => $query->time,
  15. 'url' => $query->url,
  16. 'fingerprint' => $request->fingerprint()
  17. ];
  18. });
  19. }
  20. }
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post