I am trying to use sessions in a website I'm building and I installed the CGI::Sessions module and got it to work fine, however when using it with the MySQL driver it will not save the session to the database unless the session handle is created locally within the subroutine. I'm trying to make the session accessible by everything in my program..works fine with the file driver however.
FreeBSD 4.9, MySQL 12.22, Perl v5.8.3
Here is a test script to demonstrate what I'm talkin about.
#!/usr/bin/perl
$dbn = "DBI:mysql:***";
$dbu = "***";
$dbp = "***";
use CGI;
use DBI;
use CGI::Session;
my $cgi = new CGI;
$dbh = DBI->connect($dbn, $dbu, $dbp, {RaiseError=>1,AutoCommit=>1}) o
+r die ($DBI::errstr);
&initsession;
&addanothervalue;
print $cgi->header;
print "$sessionid<p> $session<p><p>";
sub addanothervalue {
# -> comment out this line (to get working)
$session->param('test',1);
}
sub initsession {
#$session = new CGI::Session("driver:file",undef,{Directory=>'temp
+'});
# -> add my to this line below (to get working)
$session = new CGI::Session("driver:MySQL",undef,{Handle=>$dbh});
$sessionid = $session->id;
$session->expire('+1h');
}
the way it is set right now, it doesn't work - it won't save the info to the database. however if you make the session handle local - it saves it to the database with a smile.
thanks for any help,
webg