question about optimizing access to mysql

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
aneuryzma
Forum Contributor
Posts: 106
Joined: Sat May 17, 2008 7:03 am

question about optimizing access to mysql

Post 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
mickd
Forum Contributor
Posts: 397
Joined: Tue Jun 21, 2005 9:05 am
Location: Australia

Re: question about optimizing access to mysql

Post by mickd »

If i understood what you were doing correctly, it sounds very reasonable :)
petrosa
Forum Newbie
Posts: 12
Joined: Fri Feb 27, 2009 9:13 pm

Re: question about optimizing access to mysql

Post 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
aneuryzma
Forum Contributor
Posts: 106
Joined: Sat May 17, 2008 7:03 am

Re: question about optimizing access to mysql

Post 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
Post Reply