From bb3b9a428453661a5a959cb403c5747bad4e9769 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Mon, 29 Aug 2016 11:32:43 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9BQuery=E7=B1=BB=E7=9A=84select?= =?UTF-8?q?=E6=96=B9=E6=B3=95=E7=9A=84=E8=BF=94=E5=9B=9E=E7=BB=93=E6=9E=9C?= =?UTF-8?q?=E9=9B=86=E5=88=A4=E6=96=AD=20=20Connection=E7=B1=BB=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0getNumRows=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/db/Connection.php | 10 ++++++++++ library/think/db/Query.php | 4 ++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/library/think/db/Connection.php b/library/think/db/Connection.php index c18cec0f..babd6ba8 100644 --- a/library/think/db/Connection.php +++ b/library/think/db/Connection.php @@ -700,6 +700,16 @@ abstract class Connection return $this->linkID->lastInsertId($sequence); } + /** + * 获取返回或者影响的记录数 + * @access public + * @return integer + */ + public function getNumRows() + { + return $this->numRows; + } + /** * 获取最近的错误信息 * @access public diff --git a/library/think/db/Query.php b/library/think/db/Query.php index f92ffb04..84f0edcb 100644 --- a/library/think/db/Query.php +++ b/library/think/db/Query.php @@ -1883,7 +1883,7 @@ class Query } // 返回结果处理 - if ($resultSet) { + if ($this->connection->getNumRows()) { // 数据列表读取后的处理 if (!empty($this->model)) { // 生成模型对象 @@ -1898,7 +1898,7 @@ class Query } $resultSet[$key] = $result; } - if (!empty($options['with'])) { + if (!empty($options['with']) && $result instanceof Model) { // 预载入 $resultSet = $result->eagerlyResultSet($resultSet, $options['with'], is_object($resultSet) ? get_class($resultSet) : ''); }