Skip to content

Commit 0e9f8b6

Browse files
ghostffghostff
authored andcommitted
Allow reusing existing driver connection
1 parent ddf6286 commit 0e9f8b6

9 files changed

Lines changed: 1579 additions & 26 deletions

File tree

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,4 +158,24 @@ echo $session->pop('age'); # outputs 40
158158
echo $session->pop('age'); # outputs 30
159159
```
160160

161+
## Driver configuration
162+
163+
You can provide your own database connection (PDO, Memcached, Redis, etc). Provide the connection before constructing the session:
164+
```php
165+
// Example: supplying a PDO connection
166+
$pdo = new PDO('mysql:host=127.0.0.1;dbname=sessions', 'user', 'pass', [
167+
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
168+
]);
169+
170+
Session::setConnection(Session::CONFIG_MYSQL_DS, $pdo);
171+
172+
// Then construct your session (the configured driver will use this connection)
173+
$session = new Session();
174+
```
175+
176+
Similarly, you can set connections for:
177+
- `Session::CONFIG_SQLITE_DS` with a PDO SQLite connection
178+
- `Session::CONFIG_MEMCACHED_DS` with a Memcached instance
179+
- `Session::CONFIG_REDIS_DS` with a Redis instance
180+
161181

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
}
1717
},
1818
"require": {
19-
"php": ">=7.4"
19+
"php": ">=7.4",
20+
"ext-pdo": "*"
2021
},
2122
"autoload-dev": {
2223
"classmap": [

0 commit comments

Comments
 (0)