Page 1 of 1

question about optimizing access to mysql

Posted: Sat May 09, 2009 9:17 am
by aneuryzma
Hello,

I have an account page and I would like user informations (stored in mysql) if the user is logged in.

I'm using php to retrieve the data and displaying them into the account page.

Php is embedded in the account page, so everytime the user visit to the account page the data are retrieved from the database.

Is this correct ? Is it reasonable ? Or should I optimize the code in order to retrieve the datas only once from the database ?

thanks

Re: question about optimizing access to mysql

Posted: Sat May 09, 2009 9:22 am
by mickd
If i understood what you were doing correctly, it sounds very reasonable :)

Re: question about optimizing access to mysql

Posted: Sat May 09, 2009 10:20 am
by petrosa
Not sure if this what u want, but u could use sessions to give access to certain pages to your users. Just check with isset($_SESSION['username']), and if its not redirect to another page. You only retrieve the details from the DB once.

Hope this helps

Re: question about optimizing access to mysql

Posted: Sat May 09, 2009 10:52 am
by aneuryzma
all right!
so if I've understood well,

every time I access to account page
- I check if the user i loged in
- i check if the data are stored in session variables
- if they are not stored, I retrieve them from mysql and i store them in php variables