laravel框架打印最后一条执行的sql语句

代码:

DB::connection()->enableQueryLog();
$query = DB::table('test')->orderBy('id', 'desc')->get();//需要执行的SQL语句
echo '<pre>';
print_r(DB::getQueryLog());

执行结果:

Array
(
  [0] => Array
    (
      [query] => select count(*) as aggregate from `sj_real` where `real_status` = ?
      [bindings] => Array
        (
          [0] => 1
        )
  
      [time] => 225.01
    )
  
  [1] => Array
    (
      [query] => select * from `sj_real` where `real_status` = ? order by `real_id` desc limit 15 offset 0
      [bindings] => Array
        (
          [0] => 1
        )
  
      [time] => 45
    )
  
)

猜你喜欢

转载自blog.csdn.net/weixin_45849851/article/details/103347066