变更
This commit is contained in:
+11
-5
@@ -159,7 +159,7 @@ class Connection extends Component
|
|||||||
'read_timeout' => $this->read_timeout,
|
'read_timeout' => $this->read_timeout,
|
||||||
'dbname' => $this->database,
|
'dbname' => $this->database,
|
||||||
'pool' => $this->pool
|
'pool' => $this->pool
|
||||||
]);
|
], true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -168,10 +168,16 @@ class Connection extends Component
|
|||||||
*/
|
*/
|
||||||
public function getSlaveClient(): PDO
|
public function getSlaveClient(): PDO
|
||||||
{
|
{
|
||||||
if (empty($this->slaveConfig) || $this->slaveConfig['cds'] == $this->cds) {
|
return $this->connection->get([
|
||||||
return $this->getMasterClient();
|
'cds' => $this->slaveConfig['cds'] ?? $this->cds,
|
||||||
}
|
'username' => $this->slaveConfig['username'] ?? $this->username,
|
||||||
return $this->connection->get($this->slaveConfig);
|
'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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -334,17 +334,14 @@ class PDO implements StopHeartbeatCheck
|
|||||||
\PDO::ATTR_EMULATE_PREPARES => false,
|
\PDO::ATTR_EMULATE_PREPARES => false,
|
||||||
\PDO::ATTR_CASE => \PDO::CASE_NATURAL,
|
\PDO::ATTR_CASE => \PDO::CASE_NATURAL,
|
||||||
\PDO::ATTR_TIMEOUT => $this->connect_timeout,
|
\PDO::ATTR_TIMEOUT => $this->connect_timeout,
|
||||||
\PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true,
|
|
||||||
\PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES ' . $this->charset
|
\PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES ' . $this->charset
|
||||||
]);
|
]);
|
||||||
$link->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
|
$link->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
|
||||||
$link->setAttribute(\PDO::ATTR_STRINGIFY_FETCHES, false);
|
$link->setAttribute(\PDO::ATTR_STRINGIFY_FETCHES, false);
|
||||||
$link->setAttribute(\PDO::ATTR_ORACLE_NULLS, \PDO::NULL_EMPTY_STRING);
|
$link->setAttribute(\PDO::ATTR_ORACLE_NULLS, \PDO::NULL_EMPTY_STRING);
|
||||||
if (!empty($this->attributes)) {
|
|
||||||
foreach ($this->attributes as $key => $attribute) {
|
foreach ($this->attributes as $key => $attribute) {
|
||||||
$link->setAttribute($key, $attribute);
|
$link->setAttribute($key, $attribute);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return $link;
|
return $link;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user