改进Query类的column对没有查询到数据的处理

This commit is contained in:
thinkphp
2016-05-05 17:30:29 +08:00
parent b6072ebe48
commit 28a88d9937
4 changed files with 16 additions and 37 deletions

View File

@@ -1,25 +0,0 @@
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
namespace think\config\driver;
interface ConfigInterface
{
/**
* 解析配置
* @access public
* @param mixed $config 配置
* @return mixed
*/
public function parse($config);
}

View File

@@ -11,7 +11,7 @@
namespace think\config\driver;
class Ini implements ConfigInterface
class Ini
{
public function parse($config)
{

View File

@@ -11,7 +11,7 @@
namespace think\config\driver;
class Xml implements ConfigInterface
class Xml
{
public function parse($config)
{

View File

@@ -139,17 +139,21 @@ class Query
$result = $pdo->fetchAll(PDO::FETCH_COLUMN);
} else {
$resultSet = $pdo->fetchAll(PDO::FETCH_ASSOC);
$fields = array_keys($resultSet[0]);
$count = count($fields);
$key1 = array_shift($fields);
$key2 = $fields ? array_shift($fields) : '';
$key = $key ?: $key1;
foreach ($resultSet as $val) {
if ($count > 2) {
$result[$val[$key]] = $val;
} elseif (2 == $count) {
$result[$val[$key]] = $val[$key2];
if ($resultSet) {
$fields = array_keys($resultSet[0]);
$count = count($fields);
$key1 = array_shift($fields);
$key2 = $fields ? array_shift($fields) : '';
$key = $key ?: $key1;
foreach ($resultSet as $val) {
if ($count > 2) {
$result[$val[$key]] = $val;
} elseif (2 == $count) {
$result[$val[$key]] = $val[$key2];
}
}
} else {
$result = [];
}
}
if (isset($cache)) {