CGI::Se...ver::DBI(3)
π NAME π
okay so bestie, this is the manual page named CGI::Se...ver::DBI(3) β from User Contributed Perl Documentation, no cap β and the actual module is CGI::Session::Driver::DBI: Base class for native DBI-related CGI::Session drivers. π
β¨ SYNOPSIS β¨
lowkey the whole setup is just this:
require CGI::Session::Driver::DBI;
@ISA = qw( CGI::Session::Driver::DBI );
πΈ DESCRIPTION πΈ
okay so in most cases you can create a new DBI-driven CGI::Session driver by literally just making an empty driver file that inherits from CGI::Session::Driver::DBI. Thatβs exactly what sqlite does. The only reason this class doesnβt suit being a valid driver itself is that its name isnβt in lowercase. Iβm serious! π periodt.
π§ NOTES π§
CGI::Session::Driver::DBI defines the init() method, which makes the DBI handle available for drivers in the Handle object attribute no matter what \%dsn_args were used in creating the session object. If your driver requires non-standard initialization, you have to re-define init() in your .pm file β but make sure to set the 'Handle' object attribute to the database handle (the one returned by DBI->connect(...)) if you wish to inherit any of the methods from CGI::Session::Driver::DBI. π«Ά
π STORAGE π
Before you can use any DBI-based session drivers, you need to make sure a compatible database table is created for CGI::Session to work with. Following command will produce minimal requirements in most SQL databases:
CREATE TABLE sessions (
id CHAR(32) NOT NULL PRIMARY KEY,
a_session TEXT NOT NULL
);
Your session table can define additional columns, but the above two are required. Name of the session table is expected to be sessions by default. You may use a different name if you wish. To do this you have to pass TableName as part of your \%dsn_args:
$s = CGI::Session->new('driver:sqlite', undef, {TableName=>'my_sessions'});
$s = CGI::Session->new('driver:mysql', undef,
{
TableName=>'my_sessions',
DataSource=>'dbi:mysql:shopping_cart'.
});
To use different column names, change the 'create table' statement, and then simply do this:
$s = CGI::Session->new('driver:pg', undef,
{
TableName=>'session',
IdColName=>'my_id',
DataColName=>'my_data',
DataSource=>'dbi:pg:dbname=project',
});
or
$s = CGI::Session->new('driver:pg', undef,
{
TableName=>'session',
IdColName=>'my_id',
DataColName=>'my_data',
Handle=>$dbh,
});
π DRIVER ARGUMENTS π
Following driver arguments are supported:
DataSourceβ First argument to be passed toDBI->connect(). If the driver makes the database connection itself, it will also explicitly disconnect from the database when the driver object isDESTROYed.Userβ User privileged to connect to the database defined inDataSource.Passwordβ Password of theUserprivileged to connect to the database defined inDataSource.Handleβ An existing DBI database handle object. The handle can be created on demand by providing a code reference as an argument, such as"<sub{DBI-"connect}>>. This way, the database connection is only created if itβs actually needed. This can be useful when combined with a framework plugin likeCGI::Application::Plugin::Session, which creates aCGI::Sessionobject on demand as well.Handlewill override all the above arguments, if any present.TableNameβ Name of the table session data will be stored in.
π LICENSING π
For support and licensing information see CGI::Session.
okay thatβs the whole page, bestie π source/version check at the very end: perl v5.42.2, dated 2026-07-28, for CGI::Se...ver::DBI(3). mwah π
π¦ where this page comes from
- alpine 3.24: perl-cgi-session-doc 4.49-r0 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms