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

Hello Monks!

I'm using Apache::Session::MySql but i can't make that works, it not save data except _session value

# This is a previous connection my $dbh = DBI->connect('DBI:mysql:database=test;host=localhost', 'root +', ''); $dbh->do(q{SET NAMES utf8}); our %session = (); tie %session, 'Apache::Session::MySQL', undef, { Handle => $dbh, LockHandle => $dbh }; $session{some} = "asdfa5s4fd5s45f4d56af5"; # It's not saved $dbh->disconnect;

In theory this must be work, but it doesn't, i used too tied(%session)->save but nothing happend, i'm not sure what is happening

I used a BLOB field type in the db to do more precise, but still not works

What's i doing wrong?

Thank you

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

SOLVED:

This problem may occurs when use InnoDB tables on MySql 6.0.2 Alpha Community NT Debug Log, becouse Apache::Session::MySql get lock to user level, so using MyIsam was solved!

Replies are listed 'Best First'.
Re: Apache::Session::MySql don't save data
by Anonymous Monk on Feb 15, 2009 at 06:36 UTC
    You keep creating a fresh session each time you run that code. You need to create it once, and retrieve the same-session, using the session id. See Apache::Session
    use Apache::Session::MySQL; my %session; #make a fresh session for a first-time visitor tie %session, 'Apache::Session::MySQL'; #stick some stuff in it $session{visa_number} = "1234 5678 9876 5432"; #get the session id for later use my $id = $session{_session_id}; #...time passes... #get the session data back out again during some other request my %session; tie %session, 'Apache::Session::MySQL', $id; validate($session{visa_number}); #delete a session from the object store permanently tied(%session)->delete;

      Yes of course, I'm doing that but $session{visa_number} = "1234 5678 9876 5432"; is not saved, i checked in the db and don't appear so the module don't save the changes

      In fact used tied(%session)->save to flush the changes but doesn't work too

      Thank you

Re: Apache::Session::MySql don't save data
by perrin (Chancellor) on Feb 15, 2009 at 19:09 UTC

    Apache::Session doesn't save changes until it goes out of scope. If you put a session object in a global, as you do here with "our %session", it will never go out of scope. You can put it in a lexical variable or explicitly undef %session at the end of every request.

    Also... MySQL 6.0.2 Alpha?!! Are you kidding me? I hope you enjoy crashes and debugging.

      No, in my opinion it isn't, the implementation of persistent variables is in charge of the developer but when the reference count reaches zero, launch DESTROY and saves the values, in this case.

      It's not necessary to call undef, perhaps you are talking about mod_perl.

      lol! yes! i love the lastest thing so i can improve my knowledge, MySql6 has new feature and it's good to learn, i have this server for more than a year and never crash, don't be panic! of course i use it on my pc, never think in production enviroment!

      Cheers!