in reply to Problem using apache::session::store::mysql

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?

  • Comment on Re: Problem using apache::session::store::mysql

Replies are listed 'Best First'.
Re: Re: Problem using apache::session::store::mysql
by Anonymous Monk on May 25, 2004 at 15:21 UTC
    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.

        Thanks for Apache::Session overview. I wish the docs for the Apache::Session::* modules included better overviews.

        Since Apache::Session::MySQL takes care of id generation, I won't worry about the underlying method.

        I was mostly concerned with getting the apache::session/mysql interface to work before exploring the core of Apache::Session. I think I can manage from here. Thanks again!