Laravel 打印SQL语句
\DB::connection()->enableQueryLog(); //开启执行日志,加在需要打印的SQL语句之前 $list = self::where(['investorid'=>$id])->whereBetween('inserttime',[$start,$end])->where('deposit','>',0)->orderBy('id','asc')->Paginate(20); print_r(\DB::getQueryLog()); //获取查询语句、参数和执行时间
若报DB找不到,则在顶部添加如下引用(添加完后去掉上面代码中DB前的斜线):
use Illuminate\Support\Facades\DB;
打印结果类似如下:
Array ( [0] => Array ( [query] => select * from `user` where (`id` = ?) limit 1 [bindings] => Array ( [0] => 40264960 ) [time] => 1.04 //注意这里的单位是毫秒 ) )