1. 首先引入Log类:`use think\Log;`
2. 其次在调用模型查询或者修改方法之后调用日志记录调试执行的SQL语句
~~~
<?php
namespace app\index\model;
use app\common\model\RemoteModel;
use think\Config;
use think\Log;
class DCharacter extends RemoteModel
{
/**
* 等级人数计算
*
* @param int $level 等级
* @return int 等级分布人数
*/
public function doLevelCount($level)
{
$map['level'] = $level;
$count = $this->where($map)->count('level');
Log::info(self::getLastSql()); //调试SQL
return $count;
}
}
~~~