改进存储过程支持

This commit is contained in:
thinkphp
2016-05-25 19:20:12 +08:00
parent 190e870dce
commit afa64cfd21

View File

@@ -356,7 +356,8 @@ abstract class Connection
$result = $this->PDOStatement->execute(); $result = $this->PDOStatement->execute();
// 调试结束 // 调试结束
$this->debug(false); $this->debug(false);
return $this->getResult($class); $procedure = 0 === strpos(strtolower(substr(trim($sql),0,4)),'call');
return $this->getResult($class,$procedure);
} catch (\PDOException $e) { } catch (\PDOException $e) {
throw new PDOException($e, $this->config, $this->queryStr); throw new PDOException($e, $this->config, $this->queryStr);
} }
@@ -472,14 +473,18 @@ abstract class Connection
* 获得数据集 * 获得数据集
* @access protected * @access protected
* @param bool|string $class true 返回PDOStatement 字符串用于指定返回的类名 * @param bool|string $class true 返回PDOStatement 字符串用于指定返回的类名
* @param bool $procedure 是否存储过程
* @return mixed * @return mixed
*/ */
protected function getResult($class = '') protected function getResult($class = '',$procedure=false)
{ {
if (true === $class) { if (true === $class) {
// 返回PDOStatement对象处理 // 返回PDOStatement对象处理
return $this->PDOStatement; return $this->PDOStatement;
} }
if($procedure){
return $this->procedure($class);
}
$result = $this->PDOStatement->fetchAll($this->fetchType); $result = $this->PDOStatement->fetchAll($this->fetchType);
$this->numRows = count($result); $this->numRows = count($result);
@@ -501,6 +506,23 @@ abstract class Connection
return $result; return $result;
} }
/**
* 获得存储过程数据集
* @access protected
* @param bool|string $class true 返回PDOStatement 字符串用于指定返回的类名
* @return array
*/
protected function procedure($class){
$item = [];
do {
$result = $this->getResult($class);
if($result){
$item[] = $result;
}
} while ($this->PDOStatement->nextRowset());
return $result;
}
/** /**
* 执行数据库事务 * 执行数据库事务
* @access public * @access public