Which option should i go with

Discussion in 'PHP' started by oo7ml, Aug 16, 2007.

  1. #1
    Hi, when a user logs into my site a session variable is created which holds certain data about the user such as

    username, firstname, lastname, age, address, sex, email, score, place

    However most of this data is only used on two pages (although they are probably the two most used pages)

    My Question is... Should i carry all this data around in the session variable or should i carry just the $username and then query the database each time i need the rest of the data for each page.

    Which would be a better method

    1 - carry all the data around in the session variable

    2 - carry just the username and query the database each time the page loads

    thanks for your help
     
    oo7ml, Aug 16, 2007 IP
  2. ehlokoen

    ehlokoen Peon

    Messages:
    161
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I think you should just go for the session... It doesn't takes up resource, querying the mysql database does.
     
    ehlokoen, Aug 16, 2007 IP
  3. Coder

    Coder Banned

    Messages:
    311
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Go with the Session Variable Mate...
     
    Coder, Aug 16, 2007 IP
  4. oo7ml

    oo7ml Well-Known Member

    Messages:
    656
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    105
    #4
    Ok, thanks guys, but one reason that i would go with the second is... If the users score changed while they were logged in, and they then clicked into their account to check their score... the score that was outputted in the session variable would still be there instead of the most up to date score. If i queried the database each time, the latest score would be pulled from the database... do you get me... THANKS AGAIN GUYS
     
    oo7ml, Aug 16, 2007 IP
  5. ehlokoen

    ehlokoen Peon

    Messages:
    161
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #5
    you can update the session variables each time the score updates :)
     
    ehlokoen, Aug 16, 2007 IP
  6. krt

    krt Well-Known Member

    Messages:
    829
    Likes Received:
    38
    Best Answers:
    0
    Trophy Points:
    120
    #6
    Session data is stored on the server and constantly accessed, not to mention the disk space, so of course it uses server resources.

    Having said that, there is little data so storing it in a session would be better than querying the DB.
     
    krt, Aug 16, 2007 IP