变更
This commit is contained in:
+1
-1
@@ -143,7 +143,7 @@ class Command extends Component
|
|||||||
} catch (\Throwable $exception) {
|
} catch (\Throwable $exception) {
|
||||||
$result = $this->logger->addError($this->sql . '. error: ' . $exception->getMessage(), 'mysql');
|
$result = $this->logger->addError($this->sql . '. error: ' . $exception->getMessage(), 'mysql');
|
||||||
} finally {
|
} finally {
|
||||||
$this->db->release($pdo);
|
$this->db->release($pdo, true);
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+8
-9
@@ -168,7 +168,7 @@ class Connection extends Component
|
|||||||
public function getSlaveClient(): PDO
|
public function getSlaveClient(): PDO
|
||||||
{
|
{
|
||||||
if (empty($this->slaveConfig) || $this->slaveConfig['cds'] == $this->cds) {
|
if (empty($this->slaveConfig) || $this->slaveConfig['cds'] == $this->cds) {
|
||||||
return $this->getPdo();
|
return $this->getMasterClient();
|
||||||
}
|
}
|
||||||
return $this->connection->get($this->slaveConfig);
|
return $this->connection->get($this->slaveConfig);
|
||||||
}
|
}
|
||||||
@@ -215,7 +215,7 @@ class Connection extends Component
|
|||||||
if ($this->_pdo->inTransaction()) {
|
if ($this->_pdo->inTransaction()) {
|
||||||
$this->_pdo->rollback();
|
$this->_pdo->rollback();
|
||||||
}
|
}
|
||||||
$this->release($this->_pdo);
|
$this->release($this->_pdo, true);
|
||||||
$this->_pdo = null;
|
$this->_pdo = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -228,7 +228,7 @@ class Connection extends Component
|
|||||||
if ($this->_pdo->inTransaction()) {
|
if ($this->_pdo->inTransaction()) {
|
||||||
$this->_pdo->commit();
|
$this->_pdo->commit();
|
||||||
}
|
}
|
||||||
$this->release($this->_pdo);
|
$this->release($this->_pdo, true);
|
||||||
$this->_pdo = null;
|
$this->_pdo = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -251,15 +251,14 @@ class Connection extends Component
|
|||||||
* 回收链接
|
* 回收链接
|
||||||
* @throws
|
* @throws
|
||||||
*/
|
*/
|
||||||
public function release(PDO $pdo)
|
public function release(PDO $pdo, $isMaster)
|
||||||
{
|
{
|
||||||
$connections = $this->connection;
|
$connections = $this->connection;
|
||||||
if (!$pdo->inTransaction()) {
|
if (!$isMaster) {
|
||||||
$cds = $this->cds;
|
$cds = $this->slaveConfig['cds'] ?? $this->cds;
|
||||||
if (isset($this->slaveConfig['cds'])) {
|
|
||||||
$cds = $this->slaveConfig['cds'];
|
|
||||||
}
|
|
||||||
$connections->addItem($cds, $pdo);
|
$connections->addItem($cds, $pdo);
|
||||||
|
} else if (!$pdo->inTransaction()) {
|
||||||
|
$connections->addItem($this->cds, $pdo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user