LooieENG Posted July 3, 2008 Share Posted July 3, 2008 Should I store the userclass, and name in a session, or just the id and use a mysql query to get the needed information? (I'll need the username and class for each page) Link to comment https://forums.phpfreaks.com/topic/113145-which-is-the-best-way/ Share on other sites More sharing options...
lemmin Posted July 3, 2008 Share Posted July 3, 2008 I think it would be better in the session so that you aren't making an extra query to your DB every time a page is loaded. If the session variables were stored in memory, it would be quite a bit more efficient (relatively), but for some reason, I think the info is actually stored in the session file and read every time it is accessed. In either case, there is much less "looking" to do if you use the session. Link to comment https://forums.phpfreaks.com/topic/113145-which-is-the-best-way/#findComment-581324 Share on other sites More sharing options...
roopurt18 Posted July 3, 2008 Share Posted July 3, 2008 Just query it on each page load. If you leave it in the session or memory or anywhere else, then it can be changed and your session (or whatever it is) may become stale. In order to determine if the data is stale, you will have to run a query to determine if the data in the database is newer than the data you have stored anyways. So since you have to hit the DB with a query and process the results anyways, it might as well be a select query with a proper index that gets the data you need. Here's a helpful hint, database indexes are a compromise between size and speed. IF all of the data in the select query happens to be stored in the index, then the DB engine will only use the index for your select; this is the best possible case. If the select statement has columns that are not part of the index, then the DB will use the index to prune the rows and then pull the remaining columns from the actual table file on disk. So my suggestion is to keep the amount of information you need on each page down to the bare minimum and create an index on those columns. Link to comment https://forums.phpfreaks.com/topic/113145-which-is-the-best-way/#findComment-581351 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.