数据库配置参数增加resultset_type 用于设置数据集的返回类型

This commit is contained in:
thinkphp
2016-05-09 11:56:22 +08:00
parent 144a6132e6
commit ae908199eb

View File

@@ -96,6 +96,8 @@ abstract class Connection
'slave_no' => '', 'slave_no' => '',
// 是否严格检查字段是否存在 // 是否严格检查字段是否存在
'fields_strict' => true, 'fields_strict' => true,
// 数据集返回类型
'resultset_type' => Db::RESULTSET_ARRAY,
]; ];
// PDO连接参数 // PDO连接参数
@@ -233,7 +235,10 @@ abstract class Connection
} }
// 记录当前字段属性大小写设置 // 记录当前字段属性大小写设置
$this->attrCase = $params[PDO::ATTR_CASE]; $this->attrCase = $params[PDO::ATTR_CASE];
// 记录数据集返回类型
if (isset($config['resultset_type'])) {
$this->resultSetType = $config['resultset_type'];
}
try { try {
if (empty($config['dsn'])) { if (empty($config['dsn'])) {
$config['dsn'] = $this->parseDsn($config); $config['dsn'] = $this->parseDsn($config);
@@ -453,16 +458,16 @@ abstract class Connection
{ {
$result = $this->PDOStatement->fetchAll($this->fetchType); $result = $this->PDOStatement->fetchAll($this->fetchType);
$this->numRows = count($result); $this->numRows = count($result);
// 返回指定对象类
if (!empty($class)) {
return new $class($result);
}
switch ($this->resultSetType) { switch ($this->resultSetType) {
case Db::RESULTSET_COLLECTION: case Db::RESULTSET_COLLECTION:
// 返回数据集Collection对象 // 返回数据集Collection对象
$result = new Collection($result); $result = new Collection($result);
break; break;
case Db::RESULTSET_CLASS: case Db::RESULTSET_CLASS:
// 返回指定对象类
if (!empty($class)) {
$result = new $class($result);
}
break; break;
case Db::RESULTSET_ARRAY: case Db::RESULTSET_ARRAY:
default: default: