2024-05-21 14:33:56 +08:00
|
|
|
<?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";
|
|
|
|
}
|
2024-05-22 14:49:06 +08:00
|
|
|
$options = array(
|
|
|
|
\PDO::ATTR_PERSISTENT => true
|
|
|
|
);
|
2024-05-21 14:33:56 +08:00
|
|
|
$pdo = new \PDO($dsn, $username, $password);
|
|
|
|
return $pdo;
|
|
|
|
}
|
|
|
|
}
|