Skip to content

Commit 486800a

Browse files
committed
Allow set persistent connection via config
1 parent 5299938 commit 486800a

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

src/Database.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ protected function makeConfig(array $config) : array
121121
'password' => null,
122122
'schema' => null,
123123
'socket' => null,
124+
'persistent' => false,
124125
'engine' => 'InnoDB',
125126
'charset' => 'utf8mb4',
126127
'collation' => 'utf8mb4_general_ci',
@@ -196,7 +197,7 @@ protected function connect(
196197
}
197198
}
198199
$this->mysqli->real_connect(
199-
$config['host'],
200+
($config['persistent'] ? 'p:' : '') . $config['host'],
200201
$config['username'],
201202
$config['password'],
202203
$config['schema'],

tests/DatabaseTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,19 @@ public function testConnectionWithArray() : void
5555
self::assertInstanceOf(Database::class, $database);
5656
}
5757

58+
public function testPersistentConnection() : void
59+
{
60+
$database = new Database([
61+
'username' => \getenv('DB_USERNAME'),
62+
'password' => \getenv('DB_PASSWORD'),
63+
'schema' => \getenv('DB_SCHEMA'),
64+
'host' => \getenv('DB_HOST'),
65+
'port' => \getenv('DB_PORT'),
66+
'persistent' => true,
67+
]);
68+
self::assertInstanceOf(Database::class, $database);
69+
}
70+
5871
public function testConnectionFail() : void
5972
{
6073
$this->expectException(mysqli_sql_exception::class);

0 commit comments

Comments
 (0)