galvin Posted November 4, 2014 Share Posted November 4, 2014 (edited) 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 November 4, 2014 by galvin Quote Link to comment https://forums.phpfreaks.com/topic/292264-mysql-query-vs-session-get-vs-session/ Share on other sites More sharing options...
Psycho Posted November 4, 2014 Share Posted November 4, 2014 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. 1 Quote Link to comment https://forums.phpfreaks.com/topic/292264-mysql-query-vs-session-get-vs-session/#findComment-1495691 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.