Revert "改名"

This reverts commit fdf58326
This commit is contained in:
2022-01-14 16:23:15 +08:00
parent c1e480cd43
commit ac0c08f909
2 changed files with 34 additions and 23 deletions
+33 -22
View File
@@ -97,7 +97,7 @@ class Connection extends Component
/**
* @throws Exception
*/
public function fill($config)
public function fill()
{
$connections = $this->connections();
$pool = Config::get('databases.pool.max', 10);
@@ -107,34 +107,45 @@ class Connection extends Component
$connections->initConnections('Mysql:' . $this->slaveConfig['cds'], false, $pool);
}
$name = $connections->name('Mysql:' . $this->cds, true);
$config = $this->_config();
for ($i = 0; $i < $pool; $i++) {
$connections->addItem($name, $connections->create($name, [
'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
])());
$connections->addItem($name, $connections->create($name, $config)());
}
$name = $connections->name('Mysql:' . $this->cds, false);
if (empty($this->slaveConfig)) {
return;
}
$config['cds'] = $this->slaveConfig['cds'];
$config['username'] = $this->slaveConfig['username'];
$config['password'] = $this->slaveConfig['password'];
$name = $connections->name('Mysql:' . $config['cds'], false);
for ($i = 0; $i < $pool; $i++) {
$connections->addItem($name, $connections->create($name, [
'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
])());
$connections->addItem($name, $connections->create($name, $config)());
}
}
/**
* @return array
*/
private function _config(): array
{
return [
'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
];
}
/**
* @param $sql
* @return PDO
+1 -1
View File
@@ -61,7 +61,7 @@ class DatabasesProviders extends Providers
$database = $this->_settings($database);
$connection = Kiri::getDi()->create(Connection::class, [$database]);
$connection->fill($database);
$connection->fill();
$app->set($key, $connection);
}