laravel实现查询最后执行的一条sql语句的方法

2025-05-27 0 25

代码:

?

1

2

3

4
DB::connection()->enableQueryLog();

$query = DB::table('test')->orderBy('id', 'desc')->get();//需要执行的SQL语句

echo '<pre>';

print_r(DB::getQueryLog());

执行结果为:

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25
Array

(

[0] => Array

(

[query] => select count(*) as aggregate from `sj_real` where `real_status` = ?

[bindings] => Array

(

[0] => 1

)

[time] => 225.01

)

[1] => Array

(

[query] => select * from `sj_real` where `real_status` = ? order by `real_id` desc limit 15 offset 0

[bindings] => Array

(

[0] => 1

)

[time] => 45

)

)

其中query所对应的为执行的SQL语句,?则表示参数值,即bindings中的值!

以上这篇laravel实现查询最后执行的一条sql语句的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持快网idc。

原文链接:https://blog.csdn.net/robin_sky/article/details/80611849

收藏 (0) 打赏

感谢您的支持,我会继续努力的!

打开微信/支付宝扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
点赞 (0)

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

快网idc优惠网 建站教程 laravel实现查询最后执行的一条sql语句的方法 https://www.kuaiidc.com/71329.html

相关文章

发表评论
暂无评论