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
4859 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:
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
Latest Issues
Composer cannot install laravel
From 1970-01-01 08:00:00
0
0
0
Laravel Space/laravel-backup cannot be installed
From 1970-01-01 08:00:00
0
0
0
Laravel 5.1 Login laravel comes with it No more
From 1970-01-01 08:00:00
0
0
0
Why thinkphp has better performance than laravel?
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template