方式一:
// 开启执行日志
DB::enableQueryLog();
$_execute = DB::table('table_name')->where('id',1)->get();
$_rsSql = DB::getQueryLog();
dd($_execute,$_rsSql);
// $_rsSql返回:
array:1 [▼
0 => array:3 [▼
"query" => "select * from `table_name` where `id` = ?"
"bindings" => array:1 [▼
0 => 1
]
"time" => 11.59
]
]
方式二:
$_rsSql = DB::table('table_name')->where('id',1)->toSql();
dd($_rsSql);
// $_rsSql返回:
// select * from `table_name` where `id` = ?
Ps:第二种方式若想查看完整SQL语句可参见《Laravel/Lumen 扩展DB Query方法以提供完整SQL执行语句》