Posted on 2008-06-30 03:37:00-07 by nekatreven
reuse dbh handle with mysql
I'm using CGI::Session for a web app I'm working on. I wrote a small username/password verifier and then followed it with these examples (tried them one at a time, of course.)

This code does not work: (no rows appear in `sessions`.`id`)
$session=CGI::Session->new("driver:mysql", undef, { Handle => $dbh}) or die CGI::Session->errstr();

--------------------------------------------------

This code does work: (session appears and can be loaded later)
$session=CGI::Session->new('driver:mysql',undef,{ DataSource=>'dbi:mysql:test', User=>'therealuser' +, Password=>'therealpassword' }) or die CGI::Session->errstr();

I'm using the existing $dbh handle to read and write a username and password field in a table called users, which is also currently in the test database alongside the sessions table. The sessions table is identical to the one suggested in the docs. $dbh is an existing handle with the same credentials, with test specified as the database in the connect line.
Do you have any ideas? Or know what other information is needed to understand what is happening?
Direct Responses: 8199 | Write a response
Perl Weekly newsletter
A free weekly newsletter for people who are busy to read all the blogs. click here to check it out.