SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    Mar 2004
    Location
    USA
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)

    Question Sessions in MySQL

    Hi,

    How do you go about storing user sessions in MySQL. I have heard some talk about this, but I have not been able to find any tutorials and or descriptions of how this is accomplished.

    Any leads and/or small examples to get me underway would be much appreciated.

    Regards,

    - php

  2. #2
    SitePoint Wizard Sillysoft's Avatar
    Join Date
    May 2002
    Location
    United States :)
    Posts
    1,691
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by php
    Hi,

    How do you go about storing user sessions in MySQL. I have heard some talk about this, but I have not been able to find any tutorials and or descriptions of how this is accomplished.

    Any leads and/or small examples to get me underway would be much appreciated.

    Regards,

    - php
    Well correct me if Im wrong but storing a session in a db just means getting the SESSION ID and comparing when they come back right?

    Found this in a fourm:
    "You can use session_id() to get the session ID, and use that as the primary key.
    Then session_encode() will give you a string to insert into the database. Do all that at the end of your script.
    At the top of your script you can use session_decode() after extracting the session data from the database, it will set the variables automatically.

    Alternatively, you could use session_set_save_handler() and write a few functions to do the job."

    Silly

  3. #3
    SitePoint Zealot scriptfactory's Avatar
    Join Date
    Oct 2003
    Location
    Kaiserslautern, Germany
    Posts
    136
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sillysoft: You have to do a little more than compare the session ID. Database sessions also must store session information so a custom session handler is required.

    php: I use ADODB ( a database abstraction library ) and it's database session management. You might want to check it out. http://php.weblogs.com/ADODB

  4. #4
    SitePoint Wizard Sillysoft's Avatar
    Join Date
    May 2002
    Location
    United States :)
    Posts
    1,691
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by scriptfactory
    Sillysoft: You have to do a little more than compare the session ID. Database sessions also must store session information so a custom session handler is required.

    php: I use ADODB ( a database abstraction library ) and it's database session management. You might want to check it out. http://php.weblogs.com/ADODB
    Your right, my mistake:

    http://www.zend.com/publishers/excer...dev-cookbook-1

    is another one to look at

    Silly

  5. #5
    SitePoint Zealot scriptfactory's Avatar
    Join Date
    Oct 2003
    Location
    Kaiserslautern, Germany
    Posts
    136
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    But that is, yet again, a PEAR based example. I don't want to get into a huge debate about PEAR but I can include ADODB with every one of my scripts but PEAR:: DB requires... <austinpowers>PEAR</austinpowers>... and there are a great number of servers that don't support it. Not a big deal if you are writing a personal script but if you are making an app for distribution you will be affected.

  6. #6
    SitePoint Evangelist
    Join Date
    Jun 2003
    Location
    Melbourne, Australia
    Posts
    440
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by scriptfactory
    php: I use ADODB ( a database abstraction library ) and it's database session management. You might want to check it out. http://php.weblogs.com/ADODB
    Last time I checked (admittedly, a while ago), ADODB creates a new database connection just for session handling. This would be fine if your were storing your sessions in a different database to your application data, but often (especially on smaller sites or shared servers) that's not the case. A number of hosts limit the number of concurrent connections you can have, so it's be nice if ADODB gave one the option to use an existing connection. (Of course, I could always write a "wrapper" to do this, but I prefer to use the Eclipse classes which I find lighter and quicker.)

    Anyway, there's quite a good article at http://www.phpbuilder.net/columns/ying20000602.php3 complete with code. Take a look at the comments too.

    Many of the comments at php.net/manual/en/function.session-set-save-handler.php are quite useful too.

    David


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •