This commit is contained in:
as2252258@163.com
2021-05-04 04:02:47 +08:00
parent 9df9c52ce9
commit 72d91575a6
+4 -7
View File
@@ -117,14 +117,11 @@ class Connection extends Component
*/ */
private function getPdo($sql): PDO private function getPdo($sql): PDO
{ {
$connections = $this->connections();
$connections->setTimeout($this->timeout);
if ($this->isWrite($sql)) { if ($this->isWrite($sql)) {
$connect = $connections->get(['cds' => $this->cds, 'username' => $this->username, 'password' => $this->password], true); return $this->masterInstance();
} else { } else {
$connect = $connections->get(['cds' => $this->slaveConfig['cds'], 'username' => $this->username, 'password' => $this->password], false); return $this->slaveInstance();
} }
return $connect;
} }
/** /**
@@ -185,8 +182,8 @@ class Connection extends Component
*/ */
public function slaveInstance(): PDO public function slaveInstance(): PDO
{ {
if (empty($this->slaveConfig)) { if (empty($this->slaveConfig) || Db::transactionsActive()) {
$this->slaveConfig = ['cds' => $this->cds, 'username' => $this->username, 'password' => $this->password]; return $this->masterInstance();
} }
return $this->connections()->get($this->slaveConfig, false); return $this->connections()->get($this->slaveConfig, false);
} }