laravel打印SQL語句


兩種方法

第一種方法:

打印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);
    }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM