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

Apache2/ModPerl2/Mason stack. I have successfully written my first cookies! Problem is, when I try to use the %session hash in code, it doesn't seem to update. I'm tying the hash thusly:
    tie %HTML::Mason::Commands::session, 'Apache::Session::MySQL',
    ($cookies{$cookie_name} ? $cookies{$cookie_name}->value() : undef),
    {
         Handle => $dbh,
         LockHandle => $dbh
    }
    ;
And I'm trying to modify the contained info thusly:
   $sth = $dbh->prepare($sql) || die qq{Error preparing "$sql": $DBI::errstr};

   $result = $sth->execute($username, $password) || die qq{Error preparing "$sql": $DBI::errstr};

   # Get the user ID
   ($user_id) = $sth->fetchrow_array;

   # Set the user ID for this session
   $HTML::Mason::Commands::session{user_id} = $user_id;
But when I print out the guts of the session, I get no userid field.
   foreach my $key (keys %HTML::Mason::Commands::session) {
      print "key: $key<br/>value: $HTML::Mason::Commands::session{$key}<br/><br/>";
   }
...
   key: _session_id
   value: e3dc89199f3d9133dcae0fab8b68df8d
I'm new to cookies and sessions, so I'm not sure where to look, but what I've read said the %session hash should update the table automagically since it's tied a la Apache::Session::MySQL. Doesn't seem to be happening though. Help?
  • Comment on Apache::Session:MySql tied hash not updating db table