第一种方法:
DB::connection('test')->enableQueryLog();
AuctionSession::select('SessionCode', 'Name') ->where([ 'Status' => 1 ])->paginate(1);
$queries = DB::connection('test')->getQueryLog(); $a = end($queries); $tmp = str_replace('?', '"' . '%s' . '"', $a["query"]); echo vsprintf($tmp, $a['bindings']);die;
效果
select 'SessionCode'.'Name' from 'auctionsession' where Status=1 limit 1 offset 0
第二种方法:AuctionSession::select('SessionCode', 'Name')
->where([ 'Status' => 1 ])->toSql();
效果
select 'SessionCode'.'Name' from 'auctionsession' where Status=1