当前位置:首页 > CMS教程 > 其它CMS > 列表

laravel 获取某个查询的查询SQL语句方法

发布:smiling 来源: PHP粉丝网  添加日期:2022-01-01 22:13:36 浏览: 评论:0 

今天小编就为大家分享一篇laravel 获取某个查询的查询SQL语句方法,具有很好的参考价值,希望对大家有所帮助,一起跟随小编过来看看吧。

如下所示:

  1. DB::connection()->enableQueryLog();#开启执行日志 
  2. $count = DB::table('test')   //执行查询 
  3.       ->whereNull('deleted_at') 
  4.       ->where('id', '=', 3) 
  5.       ->where('Name', '=', '测试') 
  6.       ->count(); 
  7. print_r(DB::getQueryLog());  //获取查询语句、参数和执行时间 
  8.  
  9. Array 
  10. ( 
  11.   [0] => Array 
  12.     ( 
  13.       [query] => select count(*) as aggregate from `test` where `deleted_at` is null and `id` = ? and `Name` = ? 
  14.       [bindings] => Array 
  15.         ( 
  16.           [0] => 3 
  17.           [1] => 测试 
  18.         ) 
  19.    
  20.       [time] => 1 
  21.     ) 
  22.    
  23. )

Tags: laravel获取某个查询

分享到: