Laravel框架打印sql语句

  1. 在 sql执行前 开启日志 
    \DB::connection()->enableQueryLog(); // 开启
  2. sql执行后获取日志并打印
    $sqllog = \DB::getQueryLog();
    dd($sqllog);
  3. 示例:
    \DB::connection()->enableQueryLog(); // 开启
    $created_time = DB::table('reconciliation_logs_user')->where(['uid'=>$uid])->value('created_at');
    $sqllog = \DB::getQueryLog(); // 获取日志
    dd($sqllog);
  4.  
posted @ 2022-04-07 17:01  `奔跑的蜗牛  阅读(498)  评论(0编辑  收藏  举报