Page 1 of 1

Global Variables from Database

Posted: Fri Apr 21, 2006 4:25 pm
by denz
Hi All

I would like to store all my global site variables in the database. I've created all the structure, and filled the data directly to the table, but i was wondering the best way to allow all these variables to be available to the application for all users. Would it be easiest to get all users to query the variables each time they move from page to page?

Or query them once, store them as global vars, and only update them when they change? (how would i do this?)

also if i did the above, how would i get them to load initially, say is the server was rebooted, can i have like a main() function in php which loads when the first visitor visits?

Thanks

Posted: Fri Apr 21, 2006 4:34 pm
by John Cartwright
this doesn't sound like a good design to me..

why are you needed to store them as global variables? Why not initialize a session and populate it with the values within the database when the user first enters the site?
also if i did the above, how would i get them to load initially, say is the server was rebooted, can i have like a main() function in php which loads when the first visitor visits?
look into the apache configuration, you can auto.prepend a php file to be called everytime the user requests a page. If the user already has his populated session, and no updates were made since the last request, ignore the population of your session.

other than that, just include a file/class that does just this on each page they request. In a best case scenario, all your page requests are piped through your index page so you'll only need to add the include to the one file.