开发者

PHP MYSQL storing session data, question

I would like to populate my $_SESSION array with all DB data of the relevant user that just logged in.

like "FIRST_NAME" in the DB would be $_SESSION["FIRST_NAME"];

What is the way to do that properly ?

$_SESSION = $result_set; //$result_set i开发者_如何学运维s the fetched array from the DB

Yielded an error (unknown() at line 0)

thanks in advance!


I would like to populate my $_SESSION array with all DB data of the relevant user that just logged in.

Don't do this. Store only the row ID in the session, and do a database request any time you need some information.

Storing this information in the session is completely redundant, and may lead to outdated data if the user changes something in the database that isn't reflected in the session variable.


You need to specify a name for the data you're storing - you can't overwrite the $_SESSION variable completely.

EG:

$_SESSION['user_id'] = $result_set->id;

Just as Pekka said, there's rarely the need to store the entire user profile in the session when you can do a separate database call to gather this data later.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜