i'm having some trouble getting Apache::Session::MySQL to work 'out-of-the-box' as per the given docs; ie: Apache::Session states that it was designed to work under a mod-perl environment, but not necessarily so. in my case, i have successfully set up the appropriate mysql database + 'sessions' table, and using the code below, can tie the hash and can view the DB connection using the mysql text client. however, writing and reading from the tied hash is unsuccessful and no data is ever written to the mysql 'sessions' table as expected.

here is the code:

sub Restore_Session { my $class = shift; my $cgi = shift || die "No CGI handle..."; my $cookie = $cgi->cookie( $SESSION_COOKIE_NAME ); warn ( $cookie ) ? "### got session cookie '$cookie'" : "### no session cookie" ; tie %Session, 'Apache::Session::MySQL', $cookie, { 'DataSource' => "dbi:mysql:$DB_NAME;host=$HOSTNAME;por +t=$HOSTPORT", 'UserName' => $DB_USERNAME, 'Password' => $PASSWORD, 'LockDataSource' => "dbi:mysql:$DB_NAME;host=$HOSTNAME;por +t=$HOSTPORT", 'LockUserName' => $DB_USERNAME, 'LockPassword' => $PASSWORD, } ; warn "### session id is '$Session{_session_id}'"; $Session{'some crap'} = 'some value crap'; warn "### current session parameters:" . (( %Session > 0 ) ? (join "\t", '', map {"'$_' => '$Session{$_}'"} keys %Sessi +on) : " none... starting new session\n") ; return (%Session > 0); } sub Save_Session { my $class = shift; my $cgi = shift || $CGI || die "No CGI handle..."; $Session{'time_now'} = localtime(); warn "### current session parameters:" . (( %Session > 0 ) ? (join "\t", '', map {"'$_' => '$Session{$_}'"} keys %Sessi +on) : "none... saving empty session!!!\n") ; my $session_id = $Session{_session_id}; warn "### session id is '$session_id'"; return $cgi->cookie( -name => $SESSION_COOKIE, -value => $session_id, -expires => '+1h', -path => '/', ); }
the method 'Restore_Session' is called near the start of the script, and 'Save_Session' is called just prior to sending the http headers. i think i can say that there is no other funny business outside these methods which could mess around with the tied hash.

the 'warn's in this code indicate that the hash does not have any data - despite the fact that the DB table does have session id's added to it (but no data...), and that the cookie stuff all works as it should. so, it is like the tied hash is refusing to STORE or FETCH my data for some reason, or i am just missing something.

any ideas? thanks in advance...


In reply to using/debugging Apache::Session::MySQL by d_i_r_t_y

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.