From da9c41f9e7e3666c678594a09d1c9b246aeea294 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Fri, 8 Apr 2016 17:59:11 +0800 Subject: [PATCH] =?UTF-8?q?Driver=E7=B1=BB=E7=9A=84value=E6=96=B9=E6=B3=95?= =?UTF-8?q?=E6=8B=86=E5=88=86=E4=B8=BAvalue=E5=92=8Ccolumn=E6=96=B9?= =?UTF-8?q?=E6=B3=95=20=E7=94=A8=E4=BA=8E=E8=8E=B7=E5=8F=96=E5=8D=95?= =?UTF-8?q?=E4=B8=AA=E5=80=BC=20=E5=8F=8A=20=E5=88=97=E8=A1=A8=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/db/Driver.php | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/library/think/db/Driver.php b/library/think/db/Driver.php index 1f030169..add300e5 100644 --- a/library/think/db/Driver.php +++ b/library/think/db/Driver.php @@ -1002,26 +1002,33 @@ abstract class Driver } /** - * 得到某个字段的值 或者多个字段列数组 + * 得到某个字段的值 * @access public - * @param string|array $field 字段名 - * @param bool $resultSet 是否需要返回字段列表 + * @param string $field 字段名 * @return mixed */ - public function value($field, $resultSet = false) + public function value($field) { // 返回数据个数 - if (!$resultSet) { - $pdo = $this->field($field)->fetchPdo(true)->find(); - return $pdo->fetchColumn(); - } else { - $pdo = $this->field($field)->fetchPdo(true)->select(); - if (1 == $pdo->columnCount()) { - return $pdo->fetchAll(PDO::FETCH_COLUMN); - } - $result = $pdo->fetchAll(PDO::FETCH_ASSOC); - } + $pdo = $this->field($field)->fetchPdo(true)->find(); + return $pdo->fetchColumn(); + } + /** + * 得到某个列的数组 + * @access public + * @param string $field 字段名 多个字段用逗号分隔 + * @param string $key 索引 + * @return array + */ + public function column($field, $key = '') + { + $key = $key ? $key . ',' : ''; + $pdo = $this->field($key . $field)->fetchPdo(true)->select(); + if (1 == $pdo->columnCount()) { + return $pdo->fetchAll(PDO::FETCH_COLUMN); + } + $result = $pdo->fetchAll(PDO::FETCH_ASSOC); $fields = array_keys($result[0]); $count = count($fields); $key1 = array_shift($fields);