Home  >  Article  >  PHP Framework  >  Detailed explanation of laravel sql statement query

Detailed explanation of laravel sql statement query

藏色散人
藏色散人forward
2020-03-17 08:59:224783browse

When using laravel, data problems often occur due to problems with sql statements.

Recommended: laravel tutorial

By default, Laravel logs all queries running the current request in memory. However, in some cases, such as when inserting a large number of rows, this may cause the application to use excess memory. To disable the log, you can use the disableQueryLog method:

You can use it when operating DB classes or ORM

DB::connection()->enableQueryLog();  
// 获取已执行的查询数组  
DB::table('user')->orderBy('addtime','asc')->where(['status'=>1])->get();
//
$log = DB::getQueryLog();  
dd($log); //打印sql语句

There is also a way to see the native sql statement, which is Laravel Debugging tool debug bar

https://github.com/barryvdh/laravel-debugbar

The above is the detailed content of Detailed explanation of laravel sql statement query. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:segmentfault.com. If there is any infringement, please contact admin@php.cn delete