Home  >  Article  >  Backend Development  >  How Laravel records SQL statements

How Laravel records SQL statements

*文
*文Original
2018-01-02 09:58:451739browse

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);

});

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!

Statement:
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