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

I have just started using Apache::Session for the first time. Whenever I try to modify the tied hash, next time I load the session I dont get the value I added to it. Is there a problem with this module or could I be doing something wrong? I've looked over my code dozens of times. Here is a snippet:
$session_id = "dd8238bed20abbbbdf26ca6bbd9d035a"; %sess = (); tie %sess, 'Apache::Session::MySQL', $session_id, { Handle => $dbh, LockHandle => $dbh }; print "NAME: $sess{name}\n"; $sess{name} = "Marc";
I previously created that session by running the code with $session_id = undef, I am now just hard coding the session id in so I access the same session. The session id is showing in the mysql database with some binary data I cant read in the asession field. The first time this code is run, my name shouldnt print out, but every time after that it should, its not. I dont think this would matter, but I added an extra field to the mysql table, the fields go id, lastmodified, and asession, where lastmodified is a TIMESTAMP. The Apache::Session version is 1.6. Also, I tried another peice of code with Apache::Session, and I just simply got a seg fault. Has anyone experienced this before? Could it have something to do with tie? Thanks! Marc

Replies are listed 'Best First'.
Re: Apache::Session::MySQL not storing info, and sometimes seg faulting
by perrin (Chancellor) on Aug 28, 2004 at 03:37 UTC
    It's probably due to a scoping bug in your code. Do you understand that you need to let %sess go out of scope in order for this to work? It can't be a global, or else you'll have to manually undef it.