//调用内置DB方法开启查询日志
DB::connection()->enableQueryLog();
//编写orm查询
$instans = \App\Models\Users\User::where([
'id' => '152d34b2072611e9866e00163e0a620f',
'name' => '17318930996',
'level_id' => ['fdc36670fc5811e8951300163e0a620f','3e10ba9af9e111e887d400163e0a620f']
])->get();
//调用DB中的getQueryLog()获取查询记录得到SQL语句与绑定参数列表
var_dump(DB::getQueryLog());die;
具体打印结果如下:
array(1) {
[0]=>
array(3) {
["query"]=>
string(105) "select * from `users` where (`id` = ? and `name` = ? and `level_id` = ?) and `users`.`deleted_at` is null"
["bindings"]=>
array(4) {
[0]=>
string(32) "152d34b2072611e9866e00163e0a620f"
[1]=>
string(11) "17318930996"
[2]=>
string(32) "fdc36670fc5811e8951300163e0a620f"
[3]=>
string(32) "3e10ba9af9e111e887d400163e0a620f"
}
["time"]=>
float(0.49)
}
}
¥ 1.88微信扫描即可打赏
服务器好贵
网站需要运营
给点小费以表支持
评论已关闭