laravel:打印sql(10.27.0)
一,php代码:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
public function home(Request $request ){ //默认连接 DB::enableQueryLog(); $modelNews = new News(); $rowsNews = $modelNews ->getPage(0,1); $logNews = DB::getQueryLog(); //非默认连接,要指定一下 DB::connection( 'co_mysql' )->enableQueryLog(); $modelComment = new Comment(); $rowsComment = $modelComment ->getOneById(3); $logComment = DB::connection( 'co_mysql' )->getQueryLog(); //返回 $data = [ "news" => $rowsNews , "comment" => $rowsComment , "logNews" => $logNews , "logComment" => $logComment , ]; return Result::Success( $data ); } |
二,测试效果:
说明:刘宏缔的架构森林—专注it技术的博客,
网站:https://blog.imgtouch.com
原文: https://blog.imgtouch.com/index.php/2023/10/24/laravel-da-yin-sql/
代码: https://github.com/liuhongdi/ 或 https://gitee.com/liuhongdi
说明:作者:刘宏缔 邮箱: 371125307@qq.com
三,查看laravel框架的版本:
liuhongdi@lhdpc:/data/laravel/dignews$ php artisan --version
Laravel Framework 10.27.0