From 7a1dc48dfa0edd36f4cd4dea554f16215a38be47 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 19 Jan 2016 20:01:33 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0db=5Ffields=5Fstrict=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E5=8F=82=E6=95=B0=EF=BC=8C=E7=94=A8=E4=BA=8E=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E5=BD=93=E5=AD=97=E6=AE=B5=E4=B8=8D=E5=AD=98=E5=9C=A8?= =?UTF-8?q?=E7=9A=84=E6=95=B0=E6=8D=AE=E5=86=99=E5=85=A5=E7=9A=84=E6=97=B6?= =?UTF-8?q?=E5=80=99=E6=98=AF=E5=90=A6=E6=8A=9B=E5=87=BA=E5=BC=82=E5=B8=B8?= =?UTF-8?q?=20=EF=BC=8C=E9=BB=98=E8=AE=A4=E4=B8=BAtrue?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- convention.php | 1 + library/think/Model.php | 3 +++ 2 files changed, 4 insertions(+) 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])) { // 字段类型检查