swoole-framwork/core/lib/PDOPool.php
2024-05-22 14:49:06 +08:00

33 lines
923 B
PHP

<?php
namespace Core\lib;
class PDOPool extends DBPool
{
public function __construct($min = 5, $max = 10)
{
global $GLOBAL_CONFIGS;
$poolconfig = $GLOBAL_CONFIGS["dbpool"]["default"];
parent::__construct($poolconfig['min'], $poolconfig['max']);
//\Swoole\Runtime::enableCoroutine(true);
}
protected function newDB()
{
global $GLOBAL_CONFIGS;
$default = $GLOBAL_CONFIGS["db"]["default"];
{
$driver = $default["driver"];
$host = $default["host"];
$dbname = $default['database'];
$username = $default["username"];
$password = $default["password"];
$dsn = "$driver:host=$host;dbname=$dbname";
}
$options = array(
\PDO::ATTR_PERSISTENT => true
);
$pdo = new \PDO($dsn, $username, $password);
return $pdo;
}
}