diff --git a/library/think/Model.php b/library/think/Model.php index 78e6c8a4..870be43e 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -286,12 +286,10 @@ abstract class Model implements \JsonSerializable, \ArrayAccess if (false === $this->trigger('before_update', $this)) { return false; } - // 更新的时候检测字段更改 - if (!empty($this->change)) { - foreach ($data as $key => $val) { - if (!in_array($key, $this->change) && !$this->isPk($key) && !isset($this->relation[$key])) { - unset($data[$key]); - } + // 去除没有更新的字段 + foreach ($data as $key => $val) { + if (!in_array($key, $this->change) && !$this->isPk($key) && !isset($this->relation[$key])) { + unset($data[$key]); } } diff --git a/library/think/db/Driver.php b/library/think/db/Driver.php index c2c52885..0f6069fb 100644 --- a/library/think/db/Driver.php +++ b/library/think/db/Driver.php @@ -1350,6 +1350,9 @@ abstract class Driver */ protected function parseData($data, $bind) { + if (empty($data)) { + return []; + } $fields = array_keys($bind); foreach ($data as $key => $val) { if (!in_array($key, $fields, true)) { @@ -1761,7 +1764,10 @@ abstract class Driver $options = $this->_parseOptions(); $bind = $this->getTableInfo($options['table'], 'bind'); - $data = $this->parseData($data, $bind); + $data = $this->parseData($data, $bind); + if (empty($data)) { + return 0; + } $fields = array_keys($data); $values = array_values($data); // 兼容数字传入方式 @@ -1854,7 +1860,9 @@ abstract class Driver $bind = $this->getTableInfo($options['table'], 'bind'); $table = $this->parseTable($options['table']); $data = $this->parseData($data, $bind); - + if (empty($data)) { + return 0; + } foreach ($data as $key => $val) { $set[] = $key . '=' . $val; }