# man > CGI::Session::Driver::DBI

---
type: CommandReference
command: CGI::Session::Driver::DBI
mode: perldoc
section: 3pm
source: perldoc
---

## Quick Reference
- `@ISA = qw( CGI::Session::Driver::DBI );` — inherit from this base to create a new driver
- `$s = CGI::Session->new('driver:sqlite', undef, {TableName=>'sessions'});` — use a custom table name
- `$s = CGI::Session->new('driver:mysql', undef, {DataSource=>'dbi:mysql:dbname', User=>'user', Password=>'pass'});` — full DBI connection
- `$s = CGI::Session->new('driver:pg', undef, {Handle=>$dbh});` — reuse an existing database handle
- `$s = CGI::Session->new('driver:pg', undef, {Handle=>sub{DBI->connect(...)}});` — lazy connection via coderef
- `$s = CGI::Session->new('driver:sqlite', undef, {IdColName=>'my_id', DataColName=>'my_data'});` — custom column names

## Name
Base class for native DBI-related CGI::Session drivers

## Synopsis
perl
require CGI::Session::Driver::DBI;
@ISA = qw( CGI::Session::Driver::DBI );
## Driver Arguments
- `DataSource` — first argument to `DBI->connect()` (e.g., `dbi:mysql:dbname`)
- `User` — database user
- `Password` — database password
- `Handle` — an existing DBI handle, or a coderef that returns one (overrides `DataSource`/`User`/`Password`)
- `TableName` — name of the session table (default `sessions`)
- `IdColName` — column name for the session id (default `id`)
- `DataColName` — column name for the session data (default `a_session`)

## Storage
A compatible database table must exist. Minimal schema:
sql
CREATE TABLE sessions (
    id CHAR(32) NOT NULL PRIMARY KEY,
    a_session TEXT NOT NULL
);
All arguments can be passed as a hashref to `CGI::Session->new()`:
perl
$s = CGI::Session->new('driver:pg', undef, {
    TableName   => 'session',
    IdColName   => 'my_id',
    DataColName => 'my_data',
    Handle      => $dbh,
});
## See Also
- [CGI::Session](http://localhost/phpMan.php/perldoc/CGI%3A%3ASession/markdown)

## Exit Codes
Not applicable (module).