Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

CGI::Session::MySQL

by Cody Pendant (Prior)
on Aug 06, 2003 at 23:20 UTC ( [id://281642]=perlquestion: print w/replies, xml ) Need Help??

Cody Pendant has asked for the wisdom of the Perl Monks concerning the following question:

Can someone help me out by interpreting how exactly I'm supposed to use MySQL in conjunction with CGI::Session?

I've happily got it working with the default method, using files rather than a db, as demonstrated in the CGI::Session Cookbook * but I'm a bit baffled by the very sparse explanation in the MySQL variant.

I'm to use CGI::Session::MySQL? Or don't I need to, just use CGI::Session and tell it to use a MySQL driver? When I do so, I tell it a database handle, but ... then what? Should I connect to my database before I start using the module, it so that $dbh is already connected? I've tried that and it doesn't do anything, my sessions table in the db never contains any sessions.

Thanks in advance.

* The Cookbook has major glaring errors in it. It's lucky they're so glaring (filenames changing between open and close, arguments passed as sub($x, $y) in one place and as sub($y, $x) in another) or they'd be harder to fix. I wrote to the author and never heard back, who should I tell?



($_='kkvvttuubbooppuuiiffssqqffssmmiibbddllffss') =~y~b-v~a-z~s; print

Replies are listed 'Best First'.
Re: CGI::Session::MySQL
by jdtoronto (Prior) on Aug 07, 2003 at 02:59 UTC
    Here is how I do it, also based on the cookbook.
    #!/usr/bin/perl -W # # use CGI::Session; use CGI::Session::MySQL; use CGI qw(:standard); use CGI::Carp qw(fatalsToBrowser); use DBI; use strict; my $config = { DSN => 'DBI:mysql:dc151fc_session', MySQLunm => 'xxxx', MySQLpwd => 'xxxx', cartURL => 'http://xxxx.com/cgi-bin/cart.pl?cmd +='}; my $DEBUG = 1; my $cgi; my $session; my $cart; $cgi = new CGI; my $dbh = &createDBconnection( $config->{DSN}, $config->{MySQLunm}, $c +onfig->{MySQLpwd} ); $session = new CGI::Session("driver:MySQL", $cgi, {Handle=>$dbh}); my $cookie = $cgi->cookie(-name=>'CGISESSID', -value=>$session->id, -e +xpires=>'+1d'); print $cgi->header(-cookie=>$cookie);
    That code is working in may application.

    ....john

      Thank you, that looks exactly what I need.

      What's that "dc151fc_session" all about, if you don't mind my asking -- that's your table name in the db, or the db name?



      ($_='kkvvttuubbooppuuiiffssqqffssmmiibbddllffss') =~y~b-v~a-z~s; print
        Hi!

        the dc151fc_session is the database name. All my db names are prevfixed with the first seven characters of the domain name they are used by. The table name, as I recall is 'sessions' - the default expected by CGI::Session::MySQL.

        I'm glad it helped, I only got it working for the first time yesterday!

        ....john

Re: CGI::Session::MySQL
by MrCromeDome (Deacon) on Aug 07, 2003 at 18:50 UTC
    I completely understand your frustration here. Following the Tutorial and the Cookbook got me nowhere. For whatever reason, I cannot get this to work:
    use DBI; use CGI; use CGI::Session; my $request = new CGI; my $dbh = DBI->connect("DBI:mysql:orientation", "user","pass", { Raise +Error => 1}); my $session = new CGI::Session("driver:MySQL", $request, {Handle => $d +bh});
    However, this does:
    use DBI; use CGI; use CGI::Session; my $request = new CGI; my $dbh = DBI->connect("DBI:mysql:orientation", "user","pass", { Raise +Error => 1}); my $session = new CGI::Session("driver:MySQL", $request, {Handle => $d +bh, DataSource => "DBI:mysql:orientation", User => "user", Password = +> "pass"});
    I'm curious to find out why. I've tried to RTFM, but it gets me nowhere.

    MrCromeDome

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://281642]
Approved by MrCromeDome
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2024-04-20 00:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found