comphp / session-comphp-database
Session Driver for CommonPHP that reads/stores session data in a CommonPHP Database connection
Package info
github.com/commonphp/session-comphp-database
pkg:composer/comphp/session-comphp-database
Requires
- php: ^8.5
- comphp/database: ^0.3
- comphp/session: ^0.3
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.95
- phpunit/phpunit: ^13.1
This package is auto-updated.
Last update: 2026-05-21 11:55:06 UTC
README
Session driver for CommonPHP that reads and stores session data through a CommonPHP Database connection.
Requirements
- PHP
^8.5 comphp/session:^0.3comphp/database:^0.3
Installation
Once this package is available through your Composer repositories, install it with:
composer require comphp/session-comphp-database
Usage
<?php use CommonPHP\Database\DatabaseManager; use CommonPHP\Drivers\Session\CommonPHPDatabase\CommonPHPDatabaseSessionDriver; use CommonPHP\Drivers\Session\CommonPHPDatabase\CommonPHPDatabaseSessionOptions; use CommonPHP\Session\SessionManager; $database = DatabaseManager::connection('main', $databaseDriver); $driver = new CommonPHPDatabaseSessionDriver( $database, new CommonPHPDatabaseSessionOptions( table: 'sessions', sessionName: 'APPSESSID', connection: 'main', ), ); $session = new SessionManager($driver); $session->start(); $session->set('user_id', 42); $session->save();
Driver Notes
This driver is intended for applications that already use comphp/database and want session data stored through a CommonPHP database connection.
The driver should keep database-backed session storage separate from the core session package while using the common database abstraction.
By default, the driver expects a table with these unquoted SQL identifiers:
create table sessions ( id varchar(128) not null, name varchar(128) not null, payload text not null, last_activity integer not null, primary key (id, name) );
Use CommonPHPDatabaseSessionOptions to change the table, column names, session cookie name, connection name, lifetime, garbage collection odds, or generated id byte length.
Error Handling
Connection, read, write, destroy, garbage collection, and configuration failures should throw CommonPHP session or database exceptions instead of returning ambiguous false values.
Documentation
License
MIT. See LICENSE.md.