From 474916983e0e506b8b53fe2333241022e03ff829 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Thu, 18 Oct 2018 19:05:37 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9Bcount=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E7=9A=84=E8=BF=94=E5=9B=9E=E5=80=BC=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/db/Query.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/library/think/db/Query.php b/library/think/db/Query.php index 70c43a3a..ba4eff84 100644 --- a/library/think/db/Query.php +++ b/library/think/db/Query.php @@ -436,9 +436,10 @@ class Query // 返回SQL语句 return $pdo; } + $result = $pdo->fetchColumn(); if ($force) { - $result += 0; + $result = (float) $result; } if (isset($cache) && false !== $result) { @@ -538,10 +539,13 @@ class Query $options = $this->getOptions(); $subSql = $this->options($options)->field('count(' . $field . ')')->bind($this->bind)->buildSql(); - return $this->table([$subSql => '_group_count_'])->value('COUNT(*) AS tp_count', 0, true); + $count = $this->table([$subSql => '_group_count_'])->value('COUNT(*) AS tp_count', 0); + } else { + $count = $this->aggregate('COUNT', $field); } - return $this->aggregate('COUNT', $field, true); + return is_string($count) ? $count : (int) $count; + } /**