Jump to content

MySQL query vs. SESSION / GET vs SESSION?


galvin

Recommended Posts

Just curious how other people feel about this.  I am working on an application where a lot of info is pulled from MySQL and needed on multiple pages.  

 

Would it make more sense to...

 

1.  Pull all data ONCE and store it in SESSION variables to use on other pages 

 

2.  Pull the data from the database on each new page that needs it

 

I assume the preferred method is #1, but maybe there is some downside to using SESSION variables "too much"?

 

Side question that's kind of related:  As far as URLs, is it preferable to have data stored in them (i.e. domain.com/somepage.php?somedata=something&otherdata=thisdata) or use SESSION variables to store that data so the URLs can stay general/clean (i.e. domain.com/somepage.php)?

 

Both are probably loaded questions but any possible insight would be appreciated.

 

Thanks!

Greg

Edited by galvin
Link to comment
Share on other sites

The answer is "it depends". How often would this data change and how "fresh" does it need to be? If the data can change often and/or the data needs to be up to date at the time you use it (not just the value when the user logged in) then you might need to pull from the DB on page load. Also, do you need the data on all pages or only some? If only some, how often are those pages accessed? If it is only used on a small percentage of page requests, then pulling from the DB when needed may make sense. Lastly, if the data is sensitive in nature, then I think it is best to leave it in the DB (encrypted) except when you need it. Yes, session data is stored on the server, but I don't believe it is encrypted.

 

As to your second question, the answer is "It depends". :) You can still use friendly URLs along with MOD Rewrite which would convert URL path info into $_GET variables. The URL might look like this: "domain.com/somepage/something/thisdata" which would get re-written by the server to "domain.com/somepage.php?somedata=something&otherdata=thisdata". So, you would still create the page to use values in the $_GET array. Take a look at the URL for this page for an example.

 

But, it all depends on whether there is value in doing that. If you need pages to be indexed by search engines, then you definitely want to use MOD Rewrite. Otherwise I think it is more of an aesthetic issue.

  • Like 1
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.