You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by "James.Q.L" <sh...@yahoo.com> on 2003/09/01 23:05:01 UTC

Apache::Session extra record not write to Mysql db.

i am experiencing a weird problem with the use of apache::session::mysql 

before i had three fields in table sessions : a_session,id,time in the DB. 
and updating table etc from the program was working just fine. however, after i added one more
field (username) to the sessions table through phpmysql, updating it in the program
seems has no effect on the username record. no problem on others.

i am sure the username is present in the program. and i can add username record by hand through
phpmysql without problem. so i dont think it's lack of database rights. 

i also add a test record which just get timestamp. but it still don't get updated. here is code.

sub set_cookie {
    my $self = shift;
    my $sid = shift;
    $sid ||= '';
    my %session;
    &_open_db($self) unless $self->{DBH};

    eval {
            tie %session, "Apache::Session::MySQL", $sid,
                    {Handle => $self->{DBH}, LockHandle => $self->{DBH} };
    };
    croak("creating cookie error: $@\n") if ($@);

    $sid = $session{'_session_id'};
    my $uname = &get_uname($self);
    $session{'test'} = time();    ## this doesn't update 'test'
    $session{'uname'} = $uname if $uname;  ## this doesn't update 'uname'
    $session{'time'} = time();    ## this updates 'time' record
    my $cookie = Apache::Cookie->new(
                    $self->{request},
                    -name => 'ID',
                    -value => $sid,
                    -expires => $self->{CONFIG}->{cookie}->{cookie_expire},
    );
    $cookie->bake;
    return $self->{request};
}

i feel i may have done something stupid but i couldn't find it... 

Regards,

Qiang

__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com


-- 
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html


Re: Apache::Session extra record not write to Mysql db.

Posted by Anton Permyakov <an...@mail.ru>.
> > >     $session{'time'} = time();    ## this updates 'time' record
> >
> > But it doesn't update the time column in the database unless you hacked
> > the Apache::Session code to do that.
> >
>
> now i don't know why the time record gets updated. isn't it suppose to
update the one in
> a_session?

I guess 'time' field gets updated because of it is 'timestamp' type, isn't
it?
MySQL has this type for automatically updated field with current date and
time (RTFM :)).

Best wishes,
Anton Permyakov.





-- 
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html


Re: Apache::Session extra record not write to Mysql db.

Posted by Perrin Harkins <pe...@elem.com>.
On Tue, 2003-09-02 at 00:13, James.Q.L wrote:
> --- Perrin Harkins <pe...@elem.com> wrote:
> > Did you add code of your own to update the time column?
> > 
> 
> no.

Maybe you added the time column as an automatic timestamp column?  There
is no time column in the schema described in the Apache::Session
documentation.

> and from my phpmysql, you can see the time record.
> 
> id                               a_session         time     uname        test  
> 0543f2dc8dd196c5adeb29f18113f88d          20030901225218            00000000000000 

Is that a real column, or just a last-modified time that phpmysql adds
in somehow?

> and indeed as you said in record a_session it stores the session data. so if i understand
> correctly, i don't add _new_ column to the sessions table, instead i call $session{'username'} =
> 'username' which add it to the column a_session.

That's right.

> i know Apache::Session can't do session managerment directly. but i found out that when a user
> session timeout, the record also gone automatically.is tied(%session)->delete; delete the session?

Apache::Session has no concept of timeouts so it never deletes sessions,
but you can delete sessions manually with the delete method that you're
talking about.

By the way, you might find it easier to use CGI::Session.  It works fine
with mod_perl, and it directly supports things like timeouts.

- Perrin



-- 
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html


Re: Apache::Session extra record not write to Mysql db.

Posted by "James.Q.L" <sh...@yahoo.com>.
--- Perrin Harkins <pe...@elem.com> wrote:
> James.Q.L wrote:
> > before i had three fields in table sessions : a_session,id,time in the DB.
> 
> Did you add code of your own to update the time column?
> 

no.

> > and updating table etc from the program was working just fine. however, after i added one more
> > field (username) to the sessions table through phpmysql, updating it in the program
> > seems has no effect on the username record. no problem on others.
> 
> Do you understand what Apache::Session does?  It simply use Storable to 
> turn the whole hash of values into a single binary chunk and stores it 
> all in the a_session field.  It uses the id field to find the session 
> again.  It will not update any other fields unles syou hack the code 
> yourself.

I read the doc of Apache::Session::Store::Mysql but there isn't much in it.
and i tried first to have a 'time' field in the sessions table. and it did get 
updated. so that's why i thought the record get stored just like that.

and from my phpmysql, you can see the time record.

id                               a_session         time     uname        test  
0543f2dc8dd196c5adeb29f18113f88d          20030901225218            00000000000000 

and indeed as you said in record a_session it stores the session data. so if i understand
correctly, i don't add _new_ column to the sessions table, instead i call $session{'username'} =
'username' which add it to the column a_session.



> >     $session{'time'} = time();    ## this updates 'time' record
> 
> But it doesn't update the time column in the database unless you hacked 
> the Apache::Session code to do that.
> 

now i don't know why the time record gets updated. isn't it suppose to update the one in
a_session?

one more question if you don't mind.

i know Apache::Session can't do session managerment directly. but i found out that when a user
session timeout, the record also gone automatically.is tied(%session)->delete; delete the session?


Thanks

Qiang

__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com


-- 
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html


Re: Apache::Session extra record not write to Mysql db.

Posted by Perrin Harkins <pe...@elem.com>.
James.Q.L wrote:
> before i had three fields in table sessions : a_session,id,time in the DB.

Did you add code of your own to update the time column?

> and updating table etc from the program was working just fine. however, after i added one more
> field (username) to the sessions table through phpmysql, updating it in the program
> seems has no effect on the username record. no problem on others.

Do you understand what Apache::Session does?  It simply use Storable to 
turn the whole hash of values into a single binary chunk and stores it 
all in the a_session field.  It uses the id field to find the session 
again.  It will not update any other fields unles syou hack the code 
yourself.

>     $session{'test'} = time();    ## this doesn't update 'test'

That updates the field "test" in the session, which is stored as part of 
the column a_session in the database.

>     $session{'uname'} = $uname if $uname;  ## this doesn't update 'uname'

Same as above -- it updates the uname value of the session.

>     $session{'time'} = time();    ## this updates 'time' record

But it doesn't update the time column in the database unless you hacked 
the Apache::Session code to do that.

- Perrin



-- 
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html