I’m writing an application in PHP that uses a LOT of global variables that are used throughout the script. Right now, I have a config file that stores a bunch of global variables created by using the define() function, but since I’m going to have so many, would it be better to create a table in the database that is just contains variable names and values, and to access these have a function which queries the database, finds the variable, returns the value, and caches the value for future use.
I’m also welcome to other ideas for storing global variables.
The
define()function creates constants, not global variables. Global variables should be used sparingly as they can be corrupted accidentally (or maliciously!), however constants are perfectly safe.I find it easiest to just have a file named ‘config.php’ which sets up all the constants, it’s faster and simpler.