变更
This commit is contained in:
+3
-3
@@ -180,10 +180,10 @@ class Command extends Component
|
|||||||
* @return bool|int
|
* @return bool|int
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
private function _execute(): bool|int
|
private function _execute($restore = false): bool|int
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$pdo = $this->db->getPdo();
|
$pdo = $this->db->getPdo($restore);
|
||||||
if (!(($prepare = $pdo->prepare($this->sql)) instanceof PDOStatement)) {
|
if (!(($prepare = $pdo->prepare($this->sql)) instanceof PDOStatement)) {
|
||||||
throw new Exception($prepare->errorInfo()[2] ?? static::DB_ERROR_MESSAGE);
|
throw new Exception($prepare->errorInfo()[2] ?? static::DB_ERROR_MESSAGE);
|
||||||
}
|
}
|
||||||
@@ -197,7 +197,7 @@ class Command extends Component
|
|||||||
return $result == 0 ? true : $result;
|
return $result == 0 ? true : $result;
|
||||||
} catch (\PDOException|\Throwable $throwable) {
|
} catch (\PDOException|\Throwable $throwable) {
|
||||||
if (str_contains($throwable->getMessage(), 'MySQL server has gone away')) {
|
if (str_contains($throwable->getMessage(), 'MySQL server has gone away')) {
|
||||||
return $this->_execute();
|
return $this->_execute(true);
|
||||||
} else {
|
} else {
|
||||||
return $this->printErrorMessage($throwable);
|
return $this->printErrorMessage($throwable);
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-10
@@ -118,7 +118,7 @@ class Connection extends Component
|
|||||||
public function connectPoolInstance()
|
public function connectPoolInstance()
|
||||||
{
|
{
|
||||||
$pool = $this->slaveConfig['pool'] ?? ['max' => 10, 'min' => 1];
|
$pool = $this->slaveConfig['pool'] ?? ['max' => 10, 'min' => 1];
|
||||||
|
|
||||||
$this->connection->initConnections($this->cds, $pool['max']);
|
$this->connection->initConnections($this->cds, $pool['max']);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -181,14 +181,16 @@ class Connection extends Component
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @param bool $restore
|
||||||
* @return PDO
|
* @return PDO
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function getPdo(): PDO
|
public function getPdo(bool $restore = false): PDO
|
||||||
{
|
{
|
||||||
if (!Db::inTransactionsActive()) {
|
if ($restore === true) {
|
||||||
return $this->getMasterClient();
|
return Context::setContext($this->cds, $this->getMasterClient());
|
||||||
}
|
}
|
||||||
|
if (!Db::inTransactionsActive()) return $this->getMasterClient();
|
||||||
if (!Context::hasContext($this->cds)) {
|
if (!Context::hasContext($this->cds)) {
|
||||||
return Context::setContext($this->cds, $this->getMasterClient());
|
return Context::setContext($this->cds, $this->getMasterClient());
|
||||||
} else {
|
} else {
|
||||||
@@ -245,12 +247,6 @@ class Connection extends Component
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function restore()
|
|
||||||
{
|
|
||||||
Context::remove($this->cds);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* 回收链接
|
* 回收链接
|
||||||
|
|||||||
Reference in New Issue
Block a user