Home  >  Article  >  Backend Development  >  laravel 5.1 如何打印最后一次执行的sql

laravel 5.1 如何打印最后一次执行的sql

WBOY
WBOYOriginal
2016-06-06 20:16:511492browse

如何取出最后一次执行的sql

回复内容:

如何取出最后一次执行的sql

<code>DB::connection()->enableQueryLog(); // 开启查询日志

DB::table('xxx'); // 要查看的sql

$queries = DB::getQueryLog(); // 获取查询日志

print_r($queries); // 即可查看执行的sql,传入的参数等等</code>

Laravel 5.0 是這樣取出的,5.1應該也通用

<code>$queries = DB::getQueryLog();</code>

你也可以裝下這個Laravel-debugbar組件,我平時sql語句調試都是用它

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