diff --git a/convention.php b/convention.php index 33201d2e..fa1409cb 100644 --- a/convention.php +++ b/convention.php @@ -152,6 +152,7 @@ return [ // 是否启用多状态数据库配置 如果启用的话 需要跟随app_status配置不同的数据库信息 'use_db_switch' => false, + 'db_fields_strict' => true, 'database' => [ // 数据库类型 'type' => 'mysql', diff --git a/library/think/Model.php b/library/think/Model.php index 9e0a9302..c2cce2c2 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -195,6 +195,9 @@ class Model if (!empty($fields)) { foreach ($data as $key => $val) { if (!in_array($key, $fields, true)) { + if (Config::get('db_fields_strict')) { + throw new Exception(' fields not exists :[' . $key . '=>' . $val . ']'); + } unset($data[$key]); } elseif (is_scalar($val) && empty($this->options['bind'][':' . $key])) { // 字段类型检查