变更
This commit is contained in:
+6
-6
@@ -142,17 +142,17 @@ class Command extends Component
|
||||
$result = (int)$pdo->lastInsertId();
|
||||
$prepare->closeCursor();
|
||||
|
||||
$this->db->release($pdo, true);
|
||||
$this->db->release($pdo);
|
||||
|
||||
return $result == 0 ? true : $result;
|
||||
} catch (\PDOException|\Throwable $throwable) {
|
||||
if (str_contains($throwable->getMessage(), 'MySQL server has gone away')) {
|
||||
$this->db->restore(true);
|
||||
$this->db->restore();
|
||||
|
||||
return $this->_execute();
|
||||
}
|
||||
|
||||
$this->db->release($pdo,true);
|
||||
$this->db->release($pdo);
|
||||
|
||||
return $this->logger->addError($this->sql . '. error: ' . $throwable->getMessage(), 'mysql');
|
||||
}
|
||||
@@ -174,16 +174,16 @@ class Command extends Component
|
||||
$statement->bindValue($key, $param);
|
||||
}
|
||||
$data = $statement->{$type}(\PDO::FETCH_ASSOC);
|
||||
$this->db->release($pdo, false);
|
||||
$this->db->release($pdo);
|
||||
return $data;
|
||||
} catch (\Throwable $throwable) {
|
||||
if (str_contains($throwable->getMessage(), 'MySQL server has gone away')) {
|
||||
$this->db->restore(false);
|
||||
$this->db->restore();
|
||||
|
||||
return $this->search($type);
|
||||
}
|
||||
|
||||
$this->db->release($pdo, false);
|
||||
$this->db->release($pdo);
|
||||
|
||||
return $this->logger->addError($this->sql . '. error: ' . $throwable->getMessage(), 'mysql');
|
||||
}
|
||||
|
||||
+13
-31
@@ -117,15 +117,9 @@ class Connection extends Component
|
||||
*/
|
||||
public function connectPoolInstance()
|
||||
{
|
||||
if (!empty($this->slaveConfig) && isset($this->slaveConfig['cds'])) {
|
||||
$pool = $this->pool ?? ['max' => 10, 'min' => 1];
|
||||
|
||||
$this->connection->initConnections($this->slaveConfig['cds'] . 'slave', $pool['max']);
|
||||
} else {
|
||||
$pool = $this->slaveConfig['pool'] ?? ['max' => 10, 'min' => 1];
|
||||
|
||||
$this->connection->initConnections($this->cds . 'master', $pool['max']);
|
||||
}
|
||||
$pool = $this->slaveConfig['pool'] ?? ['max' => 10, 'min' => 1];
|
||||
|
||||
$this->connection->initConnections($this->cds, $pool['max']);
|
||||
}
|
||||
|
||||
|
||||
@@ -162,7 +156,7 @@ class Connection extends Component
|
||||
'read_timeout' => $this->read_timeout,
|
||||
'dbname' => $this->database,
|
||||
'pool' => $this->pool
|
||||
], true);
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -171,16 +165,7 @@ class Connection extends Component
|
||||
*/
|
||||
public function getSlaveClient(): PDO
|
||||
{
|
||||
return $this->connection->get([
|
||||
'cds' => $this->slaveConfig['cds'] ?? $this->cds,
|
||||
'username' => $this->slaveConfig['username'] ?? $this->username,
|
||||
'password' => $this->slaveConfig['password'] ?? $this->password,
|
||||
'attributes' => $this->slaveConfig['attributes'] ?? $this->attributes,
|
||||
'connect_timeout' => $this->connect_timeout,
|
||||
'read_timeout' => $this->read_timeout,
|
||||
'dbname' => $this->slaveConfig['database'] ?? $this->database,
|
||||
'pool' => $this->pool
|
||||
], false);
|
||||
return $this->getMasterClient();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -223,7 +208,7 @@ class Connection extends Component
|
||||
if ($pdo->inTransaction()) {
|
||||
$pdo->rollback();
|
||||
}
|
||||
$this->release($pdo,true);
|
||||
$this->release($pdo);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -236,7 +221,7 @@ class Connection extends Component
|
||||
if ($pdo->inTransaction()) {
|
||||
$pdo->commit();
|
||||
}
|
||||
$this->release($pdo,true);
|
||||
$this->release($pdo);
|
||||
}
|
||||
|
||||
|
||||
@@ -253,9 +238,9 @@ class Connection extends Component
|
||||
}
|
||||
|
||||
|
||||
public function restore($isMaster)
|
||||
public function restore()
|
||||
{
|
||||
Context::remove($this->alias($isMaster));
|
||||
Context::remove($this->cds);
|
||||
}
|
||||
|
||||
|
||||
@@ -264,16 +249,13 @@ class Connection extends Component
|
||||
* 回收链接
|
||||
* @throws
|
||||
*/
|
||||
public function release(PDO $PDO, bool $isMaster)
|
||||
public function release(PDO $PDO)
|
||||
{
|
||||
$name = $this->alias($isMaster);
|
||||
if ($isMaster && $PDO->inTransaction()) {
|
||||
if ($PDO->inTransaction()) {
|
||||
return;
|
||||
}
|
||||
$this->connection->addItem($name, $PDO);
|
||||
if ($isMaster) {
|
||||
Context::remove($name);
|
||||
}
|
||||
$this->connection->addItem($this->cds, $PDO);
|
||||
Context::remove($this->cds);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user