This commit is contained in:
2023-04-06 22:39:32 +08:00
parent 99b01b7f78
commit b7bcdc2096
-32
View File
@@ -95,9 +95,6 @@ class Connection extends Component
*/
public function get(string $cds): null|PDO|bool
{
if (!$this->pool->hasChannel($cds)) {
throw new Exception('Queue not exists.');
}
return $this->pool->get($cds);
}
@@ -124,35 +121,6 @@ class Connection extends Component
}
/**
* @param array $config
* @param int $max
*/
public function initConnections(array $config, int $max)
{
$this->pool->initConnections($config['cds'], $max, static function () use ($config) {
$options = [
PDO::ATTR_CASE => PDO::CASE_NATURAL,
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_ORACLE_NULLS => PDO::NULL_NATURAL,
PDO::ATTR_STRINGIFY_FETCHES => false,
PDO::ATTR_EMULATE_PREPARES => false,
PDO::ATTR_TIMEOUT => $config['connect_timeout'],
PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES ' . ($config['charset'] ?? 'utf8mb4')
];
if (!Context::inCoroutine()) {
$options[PDO::ATTR_PERSISTENT] = true;
}
$link = new PDO('mysql:dbname=' . $config['dbname'] . ';host=' . $config['cds'],
$config['username'], $config['password'], $options);
foreach ($config['attributes'] as $key => $attribute) {
$link->setAttribute($key, $attribute);
}
return $link;
});
}
/**
* @param $coroutineName
* @throws Kiri\Exception\ConfigException