Skip to content

commonphp/session-comphp-database

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CommonPHP Session CommonPHP Database Driver

Session driver for CommonPHP that reads and stores session data through a CommonPHP Database connection.

Requirements

  • PHP ^8.5
  • comphp/session:^0.3
  • comphp/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.

About

No description, website, or topics provided.

Resources

License

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages