Welcome, Guest. Please login or register.

Author Topic: Sessions in PHP+MySQL (very confused!)  (Read 4761 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline Louis Dias

Re: Sessions in PHP+MySQL (very confused!)
« Reply #14 from previous page: May 03, 2006, 12:03:58 PM »
if you're worried about performance on the webserver, just set up a dedicated database server
 

Offline Nycran

  • Newbie
  • *
  • Join Date: Apr 2006
  • Posts: 17
    • Show only replies by Nycran
    • http://www.dream-fusion.com
Re: Sessions in PHP+MySQL (very confused!)
« Reply #15 on: May 03, 2006, 01:19:41 PM »
Quote
What's a correlated subquery? My guess would be where you run a query to find a value from the database (e.g. query on session ID to find the user's name) then feed that value back in to another query (e.g. query on username to get the user's status in the game)


Spot on.  Consider the following:

SELECT username, password, (SELECT MAX(id) FROM userlog WHERE username = users.username)
FROM users

The second select is correlated with the first via the username = users.username join.  You can go nuts with these kinds of queries, correlating all over the show, but it does come with a performance cost.
 

Offline motorollinTopic starter

  • Hero Member
  • *****
  • Join Date: Nov 2005
  • Posts: 8669
    • Show only replies by motorollin
Re: Sessions in PHP+MySQL (very confused!)
« Reply #16 on: May 03, 2006, 02:40:12 PM »
I didn't know you could nest queries like that. I would do this:

SELECT username FROM users WHERE sessionID = '$_COOKIE['sessionid'];
then store the username in a variable in PHP, then do
SELECT * FROM status WHERE username = '$username';

I guess your way is more efficient (in speed and code).

--
moto
Code: [Select]
10  IT\'S THE FINAL COUNTDOWN
20  FOR C = 1 TO 2
30     DA-NA-NAAAA-NAAAA DA-NA-NA-NA-NAAAA
40     DA-NA-NAAAA-NAAAA DA-NA-NA-NA-NA-NA-NAAAAA
50  NEXT C
60  NA-NA-NAAAA
70  NA-NA NA-NA-NA-NA-NAAAA NAAA-NAAAAAAAAAAA
80  GOTO 10