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

I'm trying to get the following program to run as root but keep getting the following message when the tie statement executes:

Object does not exist in the data store at /usr/local/lib/perl5/site_perl/5.8.0/ Apache/Session/Store/DBI.pm line 93.

The docs are sketchy, so I'm not sure what object it means. What am I missing? The code follows:
#!/usr/local/bin/perl use strict; use warnings; use DBI; use DBD::mysql; use Apache::Session::MySQL; use Apache::Session::Generate::MD5; use Apache::Session::Store::MySQL; use Data::Dumper; my $dsn = "DBI:mysql:database=$db:host=$host"; my $id = Apache::Session::Generate::MD5::generate(); my $store = new Apache::Session::Store::MySQL; print Dumper( $id, $store ); #if you want Apache::Session to open new DB handles: my %session_hash; tie %session_hash, 'Apache::Session::MySQL', $id, { DataSource => 'dbi:mysql:$db', UserName => $user, Password => $password, LockDataSource => 'dbi:mysql:$db', LockUserName => $user, LockPassword => $password, }; print Dumper( \%session_hash );
TIA

Replies are listed 'Best First'.
Re: Problem using apache::session::store::mysql
by perrin (Chancellor) on May 24, 2004 at 22:25 UTC
    It's telling you that it can't find a session for the ID you're passing in. You are not supposed to pass in an ID if you want to make a new session.

    Your code isn't following the samples shown in the docs. Where are you getting this from?

      Thanks for repyling. Not initializing $id seemed to be the key. I don't recall seeing anything about it in the docs though. The author didn't include "use strict;" so it wasn't clear if $id had been previously initialized or not. I was able to get the following simplified code to insert records into the sessions table:
      #!/usr/local/bin/perl use strict; use warnings; use Apache::Session::MySQL; #if you want Apache::Session to open new DB handles: my ( $id, %hash ); my $user = 'user'; my $pass = 'pass'; my $host = 'host'; my $table = 'sessions'; my $db = 'apache_session'; tie %hash, 'Apache::Session::MySQL', $id, { DataSource => "dbi:mysql:$db:$host", UserName => $user, Password => $pass, TableName => $table, LockDataSource => "dbi:mysql:$db:$host", LockUserName => $user, LockPassword => $pass, };
      The example was obtained from the module documentation for Apache::Session::MySQL (Synopsis section). A similar example is in the Apache::Session::Store::MySQL documentation under the Configuration section. The working code above is closer to the Apache::Session::MySQL example.

      If I choose to include

      use Apache::Session::Generate::MD5;
      in the program, does that mean that Apache::Session will automatically use MD5 to generate $id (rather than whatever the default method is)? What would be the advantage?
        The examples you should be following are the ones in Apache::Session and in eg/example.perl. Just take that and replace the tie() call with the appropriate parameters for Apache::Session::MySQL, which looks like what you have now.

        You are missing something about the core structure of Apache::Session. It's a toolkit of storage, locking, and ID generation modules. The Apache::Session::MySQL module is just a pre-set configuration of those. It's little more than a config file. Look at the source and you'll see what I mean.

        If you want to choose a specific ID generation algorithm, you can't use Apache::Session::MySQL because it already has one selected. You have to use Apache::Session::Flex instead. However, the MD5 ID generator which you are trying to use is already the default for Apache::Session::MySQL, so you don't need to do anything.