0

I am new here, and i got a bit of web development skills, and because in my new project I need User information on different bits of application, I was wondering is it all right to put the whole user row in a session array or to get data each time from database if so what is the easiest way to get a column (Cell) data based on ID from MYSQL with PHP ?

Thanks

Update: to be a bit more specific like i need usertype, name , email, msgs and stuff like this.

2
  • Do you already have the database that you need to get the usertype etc. from? Are you having trouble getting the data? Commented Dec 4, 2010 at 5:16
  • Thanks for answer tandu, Yes i got the database I am wondring which way is batter putting the whole raw in session or get them from database when ever in need ? from point of resource and security ? Commented Dec 4, 2010 at 5:19

2 Answers 2

1
$link = mysql_connect('localhost','root','yourPassword')
mysql_select_db('database',$link);
$sql = 'SELECT id FROM user'
$result = mysql_query($sql,$link);

$row = mysql_fetch_assoc($result);
$_SESSION['id']=$row['id'];

           // put this id in session 
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks Bhanu, but I am wondring what is pros and cons of this over getting every bit ever time its need from database.
you use session in other pages where you required
0

Just put whatever you use on every page in the session, and get the other columns when you need them. Id assume the userid and username is what you would user every page.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.