From 027d4d5b88d0ac1e49762552cb06569dc47f9a00 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 3 May 2016 23:15:52 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9BQuery=E7=B1=BB=E7=9A=84column?= =?UTF-8?q?=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/db/Query.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/library/think/db/Query.php b/library/think/db/Query.php index e956b4f8..0f84971f 100644 --- a/library/think/db/Query.php +++ b/library/think/db/Query.php @@ -131,8 +131,10 @@ class Query $result = Cache::get($guid); } if (!$result) { - $key = ($key && '*' != $field) ? $key . ',' : ''; - $pdo = $this->field($key . $field)->fetchPdo(true)->select(); + if ($key && '*' != $field) { + $field = $key . ',' . $field; + } + $pdo = $this->field($field)->fetchPdo(true)->select(); if (1 == $pdo->columnCount()) { $result = $pdo->fetchAll(PDO::FETCH_COLUMN); } else { @@ -141,11 +143,12 @@ class Query $count = count($fields); $key1 = array_shift($fields); $key2 = $fields ? array_shift($fields) : ''; + $key = $key ?: $key1; foreach ($resultSet as $val) { if ($count > 2) { - $result[$val[$key1]] = $val; + $result[$val[$key]] = $val; } elseif (2 == $count) { - $result[$val[$key1]] = $val[$key2]; + $result[$val[$key]] = $val[$key2]; } } }