獲取sql語句
getLastSql
$res = Db::table('staff')->field('id,salary')->where('id','>',1)
->group('salary')->having('salary > 5000')->select();
$sql = Db::table('staff')->getLastSql();
halt($sql);
select(false)
$res = Db::table('staff')->field('id,salary')->where('id','>',1)
->group('salary')->having('salary > 5000')->select(false);
halt($res);
fetchSql
$res = Db::table('staff')->field('id,salary')->where('id','>',1)
->group('salary')->having('salary > 5000')->fetchSql()->select();
halt($res);
buildSql
$res = Db::table('staff')->field('id,salary')->where('id','>',1)
->group('salary')->having('salary > 5000')->buildSql();
halt($res);
監聽sql
Db::listen(function($sql, $time, $explain){
// 記錄SQL
echo $sql. ' ['.$time.'s]';
// 檢視效能分析結果
dump($explain);
});
sql級日誌記錄
本作品採用《CC 協議》,轉載必須註明作者和本文連結