1CGI::Session::Driver::DUBsIe(r3)Contributed Perl DocumenCtGaIt:i:oSnession::Driver::DBI(3)
2
3
4

NAME

6       CGI::Session::Driver::DBI - Base class for native DBI-related
7       CGI::Session drivers
8

SYNOPSIS

10           require CGI::Session::Driver::DBI;
11           @ISA = qw( CGI::Session::Driver::DBI );
12

DESCRIPTION

14       In most cases you can create a new DBI-driven CGI::Session driver by
15       simply creating an empty driver file that inherits from
16       CGI::Session::Driver::DBI. That's exactly what sqlite does. The only
17       reason why this class doesn't suit for a valid driver is its name isn't
18       in lowercase. I'm serious!
19
20   NOTES
21       CGI::Session::Driver::DBI defines init() method, which makes DBI handle
22       available for drivers in Handle - object attribute regardless of what
23       "\%dsn_args" were used in creating session object. Should your driver
24       require non-standard initialization you have to re-define init() method
25       in your .pm file, but make sure to set 'Handle' - object attribute to
26       database handle (returned by DBI->connect(...)) if you wish to inherit
27       any of the methods from CGI::Session::Driver::DBI.
28

STORAGE

30       Before you can use any DBI-based session drivers you need to make sure
31       compatible database table is created for CGI::Session to work with.
32       Following command will produce minimal requirements in most SQL
33       databases:
34
35           CREATE TABLE sessions (
36               id CHAR(32) NOT NULL PRIMARY KEY,
37               a_session TEXT NOT NULL
38           );
39
40       Your session table can define additional columns, but the above two are
41       required. Name of the session table is expected to be sessions by
42       default. You may use a different name if you wish. To do this you have
43       to pass TableName as part of your " \%dsn_args ":
44
45           $s = CGI::Session->new('driver:sqlite', undef, {TableName=>'my_sessions'});
46           $s = CGI::Session->new('driver:mysql', undef,
47           {
48               TableName=>'my_sessions',
49               DataSource=>'dbi:mysql:shopping_cart'.
50           });
51
52       To use different column names, change the 'create table' statement, and
53       then simply do this:
54
55           $s = CGI::Session->new('driver:pg', undef,
56           {
57               TableName=>'session',
58               IdColName=>'my_id',
59               DataColName=>'my_data',
60               DataSource=>'dbi:pg:dbname=project',
61           });
62
63       or
64
65           $s = CGI::Session->new('driver:pg', undef,
66           {
67               TableName=>'session',
68               IdColName=>'my_id',
69               DataColName=>'my_data',
70               Handle=>$dbh,
71           });
72

DRIVER ARGUMENTS

74       Following driver arguments are supported:
75
76       DataSource
77           First argument to be passed to DBI->connect(). If the driver makes
78           the database connection itself, it will also explicitly disconnect
79           from the database when the driver object is DESTROYed.
80
81       User
82           User privileged to connect to the database defined in "DataSource".
83
84       Password
85           Password of the User privileged to connect to the database defined
86           in "DataSource"
87
88       Handle
89           An existing DBI database handle object. The handle can be created
90           on demand by providing a code reference as a argument, such as
91           "<sub{DBI-"connect}>>.  This way, the database connection is only
92           created if it actually needed. This can be useful when combined
93           with a framework plugin like CGI::Application::Plugin::Session,
94           which creates a CGI::Session object on demand as well.
95
96           "Handle" will override all the above arguments, if any present.
97
98       TableName
99           Name of the table session data will be stored in.
100

LICENSING

102       For support and licensing information see CGI::Session
103
104
105
106perl v5.36.0                      2023-01-20      CGI::Session::Driver::DBI(3)
Impressum