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

Detailed explanation of laravel sql statement query

藏色散人
Release: 2020-03-17 08:59:22
forward
4829 people have browsed it

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语句
Copy after login

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!

Related labels:
source:segmentfault.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template