From 6e7151145bd0be84feeb2328c30ecf8d5e7aa7df Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 2 Feb 2016 10:07:14 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3Model=E7=B1=BB=E4=B8=80?= =?UTF-8?q?=E5=A4=84BUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Model.php | 9 +++++---- library/think/db/Driver.php | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/library/think/Model.php b/library/think/Model.php index f3c8e466..4a884ac4 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -234,7 +234,7 @@ class Model unset($data[$key]); } elseif (is_scalar($val) && !isset($this->options['bind'][$key])) { // 字段类型检查 - $this->_parseType($data, $key, $this->options['bind']); + $this->_parseType($this->getTableName(), $data, $key, $this->options['bind']); } } } @@ -808,7 +808,7 @@ class Model $key = trim($key); if (in_array($key, $fields, true)) { if (is_scalar($val) && empty($options['bind'][$key])) { - $this->_parseType($options['where'], $key, $options['bind']); + $this->_parseType($options['table'], $options['where'], $key, $options['bind']); } } } @@ -826,14 +826,15 @@ class Model /** * 数据类型检测 * @access protected + * @param string $table 表名 * @param array $data 数据 * @param string $key 字段名 * @param array $bind 参数绑定列表 * @return void */ - protected function _parseType(&$data, $key, &$bind) + protected function _parseType($table, &$data, $key, &$bind) { - $binds = $this->getTableInfo('', 'bind'); + $binds = $this->getTableInfo($table, 'bind'); $bind[$key] = [$data[$key], isset($binds[$key]) ? $binds[$key] : \PDO::PARAM_STR]; $data[$key] = ':' . $key; } diff --git a/library/think/db/Driver.php b/library/think/db/Driver.php index 7dd202bb..bdcae0a6 100644 --- a/library/think/db/Driver.php +++ b/library/think/db/Driver.php @@ -1114,7 +1114,7 @@ abstract class Driver */ public function getLastSql($model = '') { - return $model ? $this->modelSql[$model] : $this->queryStr; + return ($model && isset($this->modelSql[$model])) ? $this->modelSql[$model] : $this->queryStr; } /**