How to output sql statements in ThinkPHP V5.1.18

in the 3: 00 version of thinkphp, you only need to add-> sql () at the end to output the current sql statement to be executed, but how to output the sql statement in 5.1.18.

Db::name ("tab_name")-> where ($where)-> count ();

Apr.25,2021

Db::getLastSql();

enable Trace debugging

set app_trace to true
location is generally in the application/config.php
page after the Trace function is enabled, after running and your page has output, the LOGO:

LOGO Trace:

Trace6SQLTrace

of ThinkPHP will be displayed in the lower right corner of the page.

echo Db::name ('tab_name')-> fetchSql (true)-> where ($where)-> count ();

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1eaab2a-46d3b.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1eaab2a-46d3b.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?