开发手册并没提及sql插入、更新语句如何获取,只提及了查询语句sql的返回,是使用fetchSql(true)。
看了源码,tp5 返回插入sql语句、更新sql语句,同样使用 fetchSql(true) 的用法,举个栗子:
插入sql语句:
Db::name(‘table’)->fetchSql(true)->insert([ ‘field1’ => ‘xxx’, ‘field2’ => ‘zzz’]);
更新sql语句:
Db::name(‘table’)->fetchSql(true)->where([ ‘id’ => 1])->update([ ‘field1’ => ‘xxx’, ‘field2’ => ‘zzz’]);
注意:
fetchSql() 不能放在末尾,否则失效报错。