How Laravel records SQL statements

*文
Release: 2023-03-18 20:56:01
Original
1783 people have browsed it

This article brings you a Laravel SQL statement recording method (recommended). Share it with everyone and give it as a reference. I hope to be helpful.

Print sql statement, output directly after you execute the SQL statement

Method 1:

$queries = DB::getQueryLog();

$a = end($queries);

$tmp = str_replace('?', '"'.'% s'.'"', $a["query"]);

echo vsprintf($tmp, $a['bindings']);

exit;

Method 2: Pay attention to placing it above routes.php

Event::listen('illuminate.query',function($query){

var_dump($query);

});
Copy after login

The above method of recording Laravel SQL statements (recommended) This is all the content that the editor has shared with you. I hope it can give you a reference, and I hope you will support Script House more.

Related recommendations:

Laravel Redis Multiple processes take the queue problem at the same time

An elegant way to generate Gravatar avatar address using Laravel

The reason why Laravel repeatedly executes the same queue task

The above is the detailed content of How Laravel records SQL statements. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!