两种方法

第一种方法:

打印SQL默认是关闭的,需要在/vendor/illuminate/database/Connection.php中打开。

/**
     * Indicates whether queries are being logged.
     *
     * @var bool
     */
//    protected $loggingQueries = false;
    protected $loggingQueries = true;

之后可在代码中使用了:

 public function index(){
        $result = DB::select('select * from activity');

        $log = DB::getQueryLog();
        var_dump($log);
    }

第二种方法:

如果不想开启但需要临时查看,可以这样操作:

    public function index(){
        
        DB::connection()->enableQueryLog();
        
        $result = DB::select('select * from activity');

        $log = DB::getQueryLog();
        var_dump($log);
    }

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-19
  • 2022-12-23
相关资源
相似解决方案