更改模型中的Banner.php
~~~
<?php
namespace app\api\model;
use think\Db;
use think\Model;
class Banner
{
public static function getBannerById($id)
{
//$result=Db::query('select * from banner_item where banner_id=?',[$id]);
$result=Db::table('banner_item')
->fetchSql()
->where(
function ($query) use ($id){
$query->where('banner_id','=',$id);
}
)->select();
return $result;
}
}
~~~
1.打印sql語句,如上代碼,在鏈式結構中加入`fetchSql()`,

2.在index.php中加入日志初始化代碼,初始化級別為sql
```
\think\Log::init([
'type' => 'File',
'path' => LOG_PATH,
'level' => ['sql']
]);
```
運行之后便會產生日志文件
