| File | /usr/share/perl5/CGI/Session/Driver/mysql.pm | Statements Executed | 25 | Total Time | 0.009338 seconds |
| Calls | Inclusive Time | Subroutine | |
|---|---|---|---|
| 1 | 0.00880 | CGI::Session::Driver::mysql:: | store |
| 1 | 0.00003 | CGI::Session::Driver::mysql:: | init |
| 1 | 0.00003 | CGI::Session::Driver::mysql:: | table_name |
| 0 | 0 | CGI::Session::Driver::mysql:: | BEGIN |
| 0 | 0 | CGI::Session::Driver::mysql:: | _mk_dsnstr |
| Line | Stmts. | Exclusive Time | Avg. | Code |
|---|---|---|---|---|
| 1 | package CGI::Session::Driver::mysql; | |||
| 2 | ||||
| 3 | # $Id: mysql.pm 351 2006-11-24 14:16:50Z markstos $ | |||
| 4 | ||||
| 5 | 3 | 0.00003 | 0.00001 | use strict; # spent 0.00001s making 1 calls to strict::import |
| 6 | 3 | 0.00004 | 0.00001 | use Carp; # spent 0.00007s making 1 calls to Exporter::import |
| 7 | 3 | 0.00047 | 0.00016 | use CGI::Session::Driver::DBI; # spent 4e-06s making 1 calls to 1 |
| 8 | ||||
| 9 | 1 | 2e-06 | 2e-06 | @CGI::Session::Driver::mysql::ISA = qw( CGI::Session::Driver::DBI ); |
| 10 | 1 | 1e-06 | 1e-06 | $CGI::Session::Driver::mysql::VERSION = "4.20"; |
| 11 | ||||
| 12 | sub _mk_dsnstr { | |||
| 13 | my ($class, $dsn) = @_; | |||
| 14 | unless ( $class && $dsn && ref($dsn) && (ref($dsn) eq 'HASH')) { | |||
| 15 | croak "_mk_dsnstr(): usage error"; | |||
| 16 | } | |||
| 17 | ||||
| 18 | my $dsnstr = $dsn->{DataSource}; | |||
| 19 | if ( $dsn->{Socket} ) { | |||
| 20 | $dsnstr .= sprintf(";mysql_socket=%s", $dsn->{Socket}); | |||
| 21 | } | |||
| 22 | if ( $dsn->{Host} ) { | |||
| 23 | $dsnstr .= sprintf(";host=%s", $dsn->{Host}); | |||
| 24 | } | |||
| 25 | if ( $dsn->{Port} ) { | |||
| 26 | $dsnstr .= sprintf(";port=%s", $dsn->{Port}); | |||
| 27 | } | |||
| 28 | return $dsnstr; | |||
| 29 | } | |||
| 30 | ||||
| 31 | ||||
| 32 | # spent 0.00003s within CGI::Session::Driver::mysql::init which was called:
# 1 times (0.00003s) by CGI::Session::Driver::new at line 24 of /usr/share/perl5/CGI/Session/Driver.pm sub init { | |||
| 33 | 4 | 0.00002 | 4e-06 | my $self = shift; |
| 34 | if ( $self->{DataSource} && ($self->{DataSource} !~ /^dbi:mysql/i) ) { | |||
| 35 | $self->{DataSource} = "dbi:mysql:database=" . $self->{DataSource}; | |||
| 36 | } | |||
| 37 | ||||
| 38 | if ( $self->{Socket} && $self->{DataSource} ) { | |||
| 39 | $self->{DataSource} .= ';mysql_socket=' . $self->{Socket}; | |||
| 40 | } | |||
| 41 | return $self->SUPER::init(); # spent 0.00001s making 1 calls to CGI::Session::Driver::DBI::init | |||
| 42 | } | |||
| 43 | ||||
| 44 | # spent 0.00880s within CGI::Session::Driver::mysql::store which was called:
# 1 times (0.00880s) by CGI::Session::flush at line 244 of /usr/share/perl5/CGI/Session.pm sub store { | |||
| 45 | 6 | 0.00876 | 0.00146 | my $self = shift; |
| 46 | my ($sid, $datastr) = @_; | |||
| 47 | croak "store(): usage error" unless $sid && $datastr; | |||
| 48 | ||||
| 49 | my $dbh = $self->{Handle}; | |||
| 50 | $dbh->do("REPLACE INTO " . $self->table_name . " (id, a_session) VALUES(?, ?)", undef, $sid, $datastr) # spent 0.00874s making 1 calls to DBI::db::do
# spent 0.00003s making 1 calls to CGI::Session::Driver::mysql::table_name | |||
| 51 | or return $self->set_error( "store(): \$dbh->do failed " . $dbh->errstr ); | |||
| 52 | return 1; | |||
| 53 | } | |||
| 54 | ||||
| 55 | ||||
| 56 | # If the table name hasn't been defined yet, check this location for 3.x compatibility | |||
| 57 | # spent 0.00003s within CGI::Session::Driver::mysql::table_name which was called:
# 1 times (0.00003s) by CGI::Session::Driver::mysql::store at line 50 of /usr/share/perl5/CGI/Session/Driver/mysql.pm sub table_name { | |||
| 58 | 3 | 0.00002 | 5e-06 | my $self = shift; |
| 59 | unless (defined $self->{TableName}) { | |||
| 60 | $self->{TableName} = $CGI::Session::MySQL::TABLE_NAME; | |||
| 61 | } | |||
| 62 | return $self->SUPER::table_name(@_); # spent 0.00002s making 1 calls to CGI::Session::Driver::DBI::table_name | |||
| 63 | } | |||
| 64 | ||||
| 65 | 1 | 4e-06 | 4e-06 | 1; |
| 66 | ||||
| 67 | __END__; | |||
| 68 | ||||
| 69 | =pod | |||
| 70 | ||||
| 71 | =head1 NAME | |||
| 72 | ||||
| 73 | CGI::Session::Driver::mysql - CGI::Session driver for MySQL database | |||
| 74 | ||||
| 75 | =head1 SYNOPSIS | |||
| 76 | ||||
| 77 | $s = new CGI::Session( "driver:mysql", $sid); | |||
| 78 | $s = new CGI::Session( "driver:mysql", $sid, { DataSource => 'dbi:mysql:test', | |||
| 79 | User => 'sherzodr', | |||
| 80 | Password => 'hello' }); | |||
| 81 | $s = new CGI::Session( "driver:mysql", $sid, { Handle => $dbh } ); | |||
| 82 | ||||
| 83 | =head1 DESCRIPTION | |||
| 84 | ||||
| 85 | B<mysql> stores session records in a MySQL table. For details see L<CGI::Session::Driver::DBI|CGI::Session::Driver::DBI>, its parent class. | |||
| 86 | ||||
| 87 | It's especially important for the MySQL driver that the session ID column be | |||
| 88 | defined as a primary key, or at least "unique", like this: | |||
| 89 | ||||
| 90 | CREATE TABLE sessions ( | |||
| 91 | id CHAR(32) NOT NULL PRIMARY KEY, | |||
| 92 | a_session TEXT NOT NULL | |||
| 93 | ); | |||
| 94 | ||||
| 95 | =head2 DRIVER ARGUMENTS | |||
| 96 | ||||
| 97 | B<mysql> driver supports all the arguments documented in L<CGI::Session::Driver::DBI|CGI::Session::Driver::DBI>. In addition, I<DataSource> argument can optionally leave leading "dbi:mysql:" string out: | |||
| 98 | ||||
| 99 | $s = new CGI::Session( "driver:mysql", $sid, {DataSource=>'shopping_cart'}); | |||
| 100 | # is the same as: | |||
| 101 | $s = new CGI::Session( "driver:mysql", $sid, {DataSource=>'dbi:mysql:shopping_cart'}); | |||
| 102 | ||||
| 103 | =head2 BACKWARDS COMPATIBILITY | |||
| 104 | ||||
| 105 | For backwards compatibility, you can also set the table like this before calling C<new()>. However, it is not recommended because it can cause conflicts in a persistent environment. | |||
| 106 | ||||
| 107 | $CGI::Session::MySQL::TABLE_NAME = 'my_sessions'; | |||
| 108 | ||||
| 109 | =head1 LICENSING | |||
| 110 | ||||
| 111 | For support and licensing see L<CGI::Session|CGI::Session>. | |||
| 112 | ||||
| 113 | =cut |