I am starting a new project and I want to store all variables (site name, colors,etc) in the database. I have done this before and it works great.
My question is what is the best way to get the variables out of the db.
I can think of a few ways.
1) use defines to and loop through all of the variables in the db.
2)use variable variables and loop through all values in db.
3) use a function like get_variables and call that every time a variable is needed.
Which method is best , to a)keep the script fast and b)minimize impact on db server.
Thanks
site wide variables
Moderator: General Moderators
-
Tubbietoeter
- Forum Contributor
- Posts: 149
- Joined: Fri Mar 14, 2003 2:41 am
- Location: Germany
I design most of my sites with a single index.php "gateway" in which all the site pages are included. Any common values can be defined here for the whole site.
If you don't have a "gateway" file, you could create a php file with your constants / variables and include wherever you need it. More efficient than doing a query.
I prefer constants over vars since I think they're a little more secure.
If you don't have a "gateway" file, you could create a php file with your constants / variables and include wherever you need it. More efficient than doing a query.
I prefer constants over vars since I think they're a little more secure.
Agreed, McGruff.
When creating specific pages, I used to include a config file at the top of each page to ensure that I was:
a.) Always connected to my MySQL DB, since most of the programs I've written have required DB access to run.
b.) Done some simple user authentication using cookies, because most of the programs I make require some form of membership to allow access.
c.) Defined any variables I would need later on in the script, especially ones like $username, $password and $email.
When creating specific pages, I used to include a config file at the top of each page to ensure that I was:
a.) Always connected to my MySQL DB, since most of the programs I've written have required DB access to run.
b.) Done some simple user authentication using cookies, because most of the programs I make require some form of membership to allow access.
c.) Defined any variables I would need later on in the script, especially ones like $username, $password and $email.