Hello Monks,
I am trying to understand the use of Apache::Session::MySQL and I have what appears to be a couple of simple questions. I have found the following code in a number of pages on the Net as an example for setting up sessions. My question is how does the code below know where to find my table and a field to update with in my table? Is 'dbi:mysql:sessions' supposed to be replaced with 'DBI:mysql:database=$database;host=$hostname;port=$port'? I have a feeling I am misunderstanding something somewhere, but I can't figure out what it is. Thank You.
# pull in the required packages
use Apache::Session::MySQL;
use Apache;
use strict;
# read in the cookie if this is an old session
my $r = Apache->request;
my $cookie = $r->header_in('Cookie');
$cookie =~ s/SESSION_ID=(\w+)/$1/;
# create a session object based on the cookie we got from the
# browser, or a new session if we got no cookie
my %session;
eval {
tie %session, 'Apache::Session::MySQL', $cookie,
{DataSource => 'dbi:mysql:sessions',
UserName => $db_user,
Password => $db_pass,
LockDataSource => 'dbi:mysql:sessions',
LockUserName => $db_user,
LockPassword => $db_pass,
};
};
if ($@) {
# could be a database problem
die "Couldn't tie session: $@";
}
# might be a new session, so let's give them their cookie back
my $session_cookie = "SESSION_ID=$session{_session_id};";
$r->header_out("Set-Cookie" => $session_cookie);
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.