变更
This commit is contained in:
@@ -5,7 +5,7 @@ namespace Kiri\Pool;
|
|||||||
|
|
||||||
use Closure;
|
use Closure;
|
||||||
use Database\Db;
|
use Database\Db;
|
||||||
use Database\Mysql\PDO;
|
use PDO;
|
||||||
use Exception;
|
use Exception;
|
||||||
use Kiri;
|
use Kiri;
|
||||||
use Kiri\Abstracts\Component;
|
use Kiri\Abstracts\Component;
|
||||||
@@ -13,7 +13,6 @@ use Kiri\Abstracts\Config;
|
|||||||
use Kiri\Context;
|
use Kiri\Context;
|
||||||
use Swoole\Error;
|
use Swoole\Error;
|
||||||
use Throwable;
|
use Throwable;
|
||||||
use Kiri\Abstracts\CoordinatorManager;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class Connection
|
* Class Connection
|
||||||
@@ -95,7 +94,7 @@ class Connection extends Component
|
|||||||
* @return PDO|null
|
* @return PDO|null
|
||||||
* @throws Kiri\Exception\ConfigException
|
* @throws Kiri\Exception\ConfigException
|
||||||
*/
|
*/
|
||||||
public function get(mixed $config, bool $isMaster = false): ?PDO
|
public function get(mixed $config, bool $isMaster = false): ?\PDO
|
||||||
{
|
{
|
||||||
$minx = Config::get('databases.pool.min', 1);
|
$minx = Config::get('databases.pool.min', 1);
|
||||||
|
|
||||||
@@ -110,14 +109,22 @@ class Connection extends Component
|
|||||||
public function generate(array $config): Closure
|
public function generate(array $config): Closure
|
||||||
{
|
{
|
||||||
return static function () use ($config) {
|
return static function () use ($config) {
|
||||||
$connect = new PDO($config);
|
$link = new \PDO('mysql:dbname=' . $config['dbname'] . ';host=' . $config['cds'], $config['username'], $config['password'], [
|
||||||
if (!Db::inTransactionsActive()) {
|
\PDO::ATTR_EMULATE_PREPARES => false,
|
||||||
return $connect;
|
\PDO::ATTR_CASE => \PDO::CASE_NATURAL,
|
||||||
|
\PDO::ATTR_TIMEOUT => $config['connect_timeout'],
|
||||||
|
\PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES ' . ($config['charset'] ?? 'utf8mb4')
|
||||||
|
]);
|
||||||
|
$link->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
|
||||||
|
$link->setAttribute(\PDO::ATTR_STRINGIFY_FETCHES, false);
|
||||||
|
$link->setAttribute(\PDO::ATTR_ORACLE_NULLS, \PDO::NULL_EMPTY_STRING);
|
||||||
|
foreach ($config['attributes'] as $key => $attribute) {
|
||||||
|
$link->setAttribute($key, $attribute);
|
||||||
}
|
}
|
||||||
if (!$connect->inTransaction()) {
|
if (Db::inTransactionsActive()) {
|
||||||
$connect->beginTransaction();
|
$link->beginTransaction();
|
||||||
}
|
}
|
||||||
return $connect;
|
return $link;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user