From 1d809efda8d8147995c9e9f67fe65943ff4a0019 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=91=E6=9E=97?= Date: Fri, 25 Feb 2022 18:16:50 +0800 Subject: [PATCH] modify plugin name --- Connection.php | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/Connection.php b/Connection.php index cec4976..3c3ae3a 100644 --- a/Connection.php +++ b/Connection.php @@ -183,16 +183,8 @@ class Connection extends Component */ public function beginTransaction(): static { - $this->connections()->beginTransaction([ - 'cds' => $this->cds, - 'username' => $this->username, - 'password' => $this->password, - 'attributes' => $this->attributes, - 'connect_timeout' => $this->connect_timeout, - 'read_timeout' => $this->read_timeout, - 'dbname' => $this->database, - 'pool' => $this->pool - ]); + $pdo = $this->masterInstance(); + $pdo->beginTransaction(); return $this; } @@ -202,7 +194,8 @@ class Connection extends Component */ public function inTransaction(): bool|static { - return $this->connections()->inTransaction($this->cds); + $pdo = $this->masterInstance(); + return $pdo->inTransaction(); } /** @@ -211,12 +204,12 @@ class Connection extends Component */ public function rollback() { - $this->connections()->rollback($this->cds); - $pdo = Context::getContext($this->cds); + $pdo = $this->masterInstance(); Context::remove($this->cds); - if ($pdo instanceof PDO) { - $this->release($pdo, $this->cds); + if ($pdo->inTransaction()) { + $pdo->rollback(); } + $this->release($pdo, $this->cds); } /** @@ -225,12 +218,12 @@ class Connection extends Component */ public function commit() { - $this->connections()->commit($this->cds); - $pdo = Context::getContext($this->cds); + $pdo = $this->masterInstance(); Context::remove($this->cds); - if ($pdo instanceof PDO) { - $this->release($pdo, $this->cds); + if ($pdo->inTransaction()) { + $pdo->commit(); } + $this->release($pdo, $this->cds); }