变更
This commit is contained in:
+12
-14
@@ -52,7 +52,7 @@ class Connection extends Component
|
||||
|
||||
public int $read_timeout = 10;
|
||||
|
||||
public array $pool;
|
||||
public array $pool = ['max' => 10, 'min' => 1];
|
||||
|
||||
|
||||
private PoolConnection $connection;
|
||||
@@ -118,9 +118,16 @@ class Connection extends Component
|
||||
*/
|
||||
public function connectPoolInstance()
|
||||
{
|
||||
$pool = $this->slaveConfig['pool'] ?? ['max' => 10, 'min' => 1];
|
||||
|
||||
$this->connection->initConnections($this->cds, $pool['max']);
|
||||
$this->connection->initConnections([
|
||||
'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
|
||||
], $this->pool['max']);
|
||||
}
|
||||
|
||||
|
||||
@@ -148,16 +155,7 @@ class Connection extends Component
|
||||
*/
|
||||
public function getMasterClient(): Mysql\PDO
|
||||
{
|
||||
return $this->connection->get([
|
||||
'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
|
||||
]);
|
||||
return $this->connection->get($this->cds);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace Database\Mysql;
|
||||
|
||||
use Database\Db;
|
||||
use Exception;
|
||||
use Kiri;
|
||||
use Kiri\Events\EventProvider;
|
||||
@@ -362,6 +363,7 @@ class PDO implements StopHeartbeatCheck
|
||||
$link = new \PDO('mysql:dbname=' . $this->dbname . ';host=' . $this->cds, $this->username, $this->password, [
|
||||
\PDO::ATTR_EMULATE_PREPARES => false,
|
||||
\PDO::ATTR_CASE => \PDO::CASE_NATURAL,
|
||||
\PDO::ATTR_PERSISTENT => true,
|
||||
\PDO::ATTR_TIMEOUT => $this->connect_timeout,
|
||||
\PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES ' . $this->charset
|
||||
]);
|
||||
@@ -371,6 +373,9 @@ class PDO implements StopHeartbeatCheck
|
||||
foreach ($this->attributes as $key => $attribute) {
|
||||
$link->setAttribute($key, $attribute);
|
||||
}
|
||||
if (Db::inTransactionsActive()) {
|
||||
$link->beginTransaction();
|
||||
}
|
||||
return $link;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user