Skip to content

Commit

Permalink
support database connect
Browse files Browse the repository at this point in the history
  • Loading branch information
wpjscc committed Feb 28, 2025
1 parent 1d3ee76 commit a207fbe
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"php": "^8.1",
"react/async": "^4 || ^3 || ^2",
"illuminate/database": "^11.19",
"reactphp-x/mysql-pool": "^2.0@dev"
"reactphp-x/mysql-pool": "^2.0"
},
"autoload": {
"psr-4": {
Expand Down
8 changes: 4 additions & 4 deletions src/AsyncMysqlConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
class AsyncMysqlConnector implements ConnectorInterface
{

protected static $pool;
protected static $connectToPoll;

public function connect($config)
{

if (static::$pool) {
return static::$pool;
if (isset(static::$connectToPoll[$config['name']])) {
return static::$connectToPoll[$config['name']];
}

$username = $config['username'];
Expand All @@ -27,7 +27,7 @@ public function connect($config)
}
$database = $config['database'];

return static::$pool = new Pool(
return static::$connectToPoll[$config['name']] = new Pool(
$username . ':' . $password . '@' . $host . '/' . $database . '?charset=' . $charset.'&idle='.($config['idle'] ?? 30),
$config['pool']['min_connections'] ?? 1,
$config['pool']['max_connections'] ?? 10,
Expand Down

0 comments on commit a207fbe

Please sign in to comment.