From 2bc267a6aa4eb4a0917adcf3ec97f2e0a0ceb9a5 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Sun, 17 Apr 2016 09:44:40 +0800 Subject: [PATCH] =?UTF-8?q?insert=E5=92=8Cupdate=E6=96=B9=E6=B3=95?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BD=BF=E7=94=A8field=E6=96=B9=E6=B3=95?= =?UTF-8?q?=E8=BF=87=E6=BB=A4=E5=86=99=E5=85=A5=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/db/Builder.php | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/library/think/db/Builder.php b/library/think/db/Builder.php index 3e43822d..892048c2 100644 --- a/library/think/db/Builder.php +++ b/library/think/db/Builder.php @@ -69,8 +69,13 @@ abstract class Builder } // 获取绑定信息 - $bind = $this->connection->getTableInfo($options['table'], 'bind'); - $fields = array_keys($bind); + $bind = $this->connection->getTableInfo($options['table'], 'bind'); + if ('*' == $options['field']) { + $fields = array_keys($bind); + } else { + $fields = is_array($options['field']) ? $options['field'] : explode(',', $options['field']); + } + $result = []; foreach ($data as $key => $val) { if (!in_array($key, $fields, true)) { @@ -543,8 +548,13 @@ abstract class Builder */ public function insertAll($dataSet, $options) { - // 获取绑定信息 - $fields = $this->connection->getTableInfo($options['table'], 'fields'); + // 获取合法的字段 + if ('*' == $options['field']) { + $fields = $this->connection->getTableInfo($options['table'], 'fields'); + } else { + $fields = is_array($options['field']) ? $options['field'] : explode(',', $options['field']); + } + foreach ($dataSet as &$data) { foreach ($data as $key => $val) { if (!in_array($key, $fields, true)) {