更新tp5内核
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
// +----------------------------------------------------------------------
|
||||
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2006~2017 http://thinkphp.cn All rights reserved.
|
||||
// | Copyright (c) 2006~2018 http://thinkphp.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||
// +----------------------------------------------------------------------
|
||||
@@ -338,8 +338,8 @@ abstract class Connection
|
||||
* @param bool $master 是否在主服务器读操作
|
||||
* @param bool $pdo 是否返回PDO对象
|
||||
* @return mixed
|
||||
* @throws BindParamException
|
||||
* @throws PDOException
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function query($sql, $bind = [], $master = false, $pdo = false)
|
||||
{
|
||||
@@ -354,15 +354,15 @@ abstract class Connection
|
||||
$this->bind = $bind;
|
||||
}
|
||||
|
||||
// 释放前次的查询结果
|
||||
if (!empty($this->PDOStatement)) {
|
||||
$this->free();
|
||||
}
|
||||
|
||||
Db::$queryTimes++;
|
||||
try {
|
||||
// 调试开始
|
||||
$this->debug(true);
|
||||
|
||||
// 释放前次的查询结果
|
||||
if (!empty($this->PDOStatement)) {
|
||||
$this->free();
|
||||
}
|
||||
// 预处理
|
||||
if (empty($this->PDOStatement)) {
|
||||
$this->PDOStatement = $this->linkID->prepare($sql);
|
||||
@@ -386,6 +386,11 @@ abstract class Connection
|
||||
return $this->close()->query($sql, $bind, $master, $pdo);
|
||||
}
|
||||
throw new PDOException($e, $this->config, $this->getLastsql());
|
||||
} catch (\Throwable $e) {
|
||||
if ($this->isBreak($e)) {
|
||||
return $this->close()->query($sql, $bind, $master, $pdo);
|
||||
}
|
||||
throw $e;
|
||||
} catch (\Exception $e) {
|
||||
if ($this->isBreak($e)) {
|
||||
return $this->close()->query($sql, $bind, $master, $pdo);
|
||||
@@ -400,8 +405,8 @@ abstract class Connection
|
||||
* @param string $sql sql指令
|
||||
* @param array $bind 参数绑定
|
||||
* @return int
|
||||
* @throws BindParamException
|
||||
* @throws PDOException
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function execute($sql, $bind = [])
|
||||
{
|
||||
@@ -416,15 +421,15 @@ abstract class Connection
|
||||
$this->bind = $bind;
|
||||
}
|
||||
|
||||
//释放前次的查询结果
|
||||
if (!empty($this->PDOStatement) && $this->PDOStatement->queryString != $sql) {
|
||||
$this->free();
|
||||
}
|
||||
|
||||
Db::$executeTimes++;
|
||||
try {
|
||||
// 调试开始
|
||||
$this->debug(true);
|
||||
|
||||
//释放前次的查询结果
|
||||
if (!empty($this->PDOStatement) && $this->PDOStatement->queryString != $sql) {
|
||||
$this->free();
|
||||
}
|
||||
// 预处理
|
||||
if (empty($this->PDOStatement)) {
|
||||
$this->PDOStatement = $this->linkID->prepare($sql);
|
||||
@@ -449,6 +454,11 @@ abstract class Connection
|
||||
return $this->close()->execute($sql, $bind);
|
||||
}
|
||||
throw new PDOException($e, $this->config, $this->getLastsql());
|
||||
} catch (\Throwable $e) {
|
||||
if ($this->isBreak($e)) {
|
||||
return $this->close()->execute($sql, $bind);
|
||||
}
|
||||
throw $e;
|
||||
} catch (\Exception $e) {
|
||||
if ($this->isBreak($e)) {
|
||||
return $this->close()->execute($sql, $bind);
|
||||
@@ -466,6 +476,10 @@ abstract class Connection
|
||||
*/
|
||||
public function getRealSql($sql, array $bind = [])
|
||||
{
|
||||
if (is_array($sql)) {
|
||||
$sql = implode(';', $sql);
|
||||
}
|
||||
|
||||
foreach ($bind as $key => $val) {
|
||||
$value = is_array($val) ? $val[0] : $val;
|
||||
$type = is_array($val) ? $val[1] : PDO::PARAM_STR;
|
||||
@@ -478,8 +492,8 @@ abstract class Connection
|
||||
$sql = is_numeric($key) ?
|
||||
substr_replace($sql, $value, strpos($sql, '?'), 1) :
|
||||
str_replace(
|
||||
[':' . $key . ')', ':' . $key . ',', ':' . $key . ' '],
|
||||
[$value . ')', $value . ',', $value . ' '],
|
||||
[':' . $key . ')', ':' . $key . ',', ':' . $key . ' ', ':' . $key . PHP_EOL],
|
||||
[$value . ')', $value . ',', $value . ' ', $value . PHP_EOL],
|
||||
$sql . ' ');
|
||||
}
|
||||
return rtrim($sql);
|
||||
@@ -552,7 +566,7 @@ abstract class Connection
|
||||
* @access protected
|
||||
* @param bool $pdo 是否返回PDOStatement
|
||||
* @param bool $procedure 是否存储过程
|
||||
* @return array
|
||||
* @return PDOStatement|array
|
||||
*/
|
||||
protected function getResult($pdo = false, $procedure = false)
|
||||
{
|
||||
@@ -618,7 +632,8 @@ abstract class Connection
|
||||
/**
|
||||
* 启动事务
|
||||
* @access public
|
||||
* @return void
|
||||
* @return bool|mixed
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function startTrans()
|
||||
{
|
||||
@@ -642,7 +657,12 @@ abstract class Connection
|
||||
return $this->close()->startTrans();
|
||||
}
|
||||
throw $e;
|
||||
} catch (\ErrorException $e) {
|
||||
} catch (\Exception $e) {
|
||||
if ($this->isBreak($e)) {
|
||||
return $this->close()->startTrans();
|
||||
}
|
||||
throw $e;
|
||||
} catch (\Error $e) {
|
||||
if ($this->isBreak($e)) {
|
||||
return $this->close()->startTrans();
|
||||
}
|
||||
@@ -724,7 +744,7 @@ abstract class Connection
|
||||
* @param array $sqlArray SQL批处理指令
|
||||
* @return boolean
|
||||
*/
|
||||
public function batchQuery($sqlArray = [])
|
||||
public function batchQuery($sqlArray = [], $bind = [])
|
||||
{
|
||||
if (!is_array($sqlArray)) {
|
||||
return false;
|
||||
@@ -733,7 +753,7 @@ abstract class Connection
|
||||
$this->startTrans();
|
||||
try {
|
||||
foreach ($sqlArray as $sql) {
|
||||
$this->execute($sql);
|
||||
$this->execute($sql, $bind);
|
||||
}
|
||||
// 提交事务
|
||||
$this->commit();
|
||||
@@ -741,6 +761,7 @@ abstract class Connection
|
||||
$this->rollback();
|
||||
throw $e;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -782,7 +803,7 @@ abstract class Connection
|
||||
/**
|
||||
* 是否断线
|
||||
* @access protected
|
||||
* @param \PDOException $e 异常对象
|
||||
* @param \PDOException|\Exception $e 异常对象
|
||||
* @return bool
|
||||
*/
|
||||
protected function isBreak($e)
|
||||
|
||||
Reference in New Issue
Block a user