Reputation: 501
Unfortunately searching for this kind of material produces a lot of noise for me so I was wondering if anyone here knew of a good resource for anyone wishing to learn how to use a database to store site configuration info rather than a file.
I guess some points I'm interested in are: 1) How to store the data. One array like e107? Separate row for each configurable? 2) How to get the configuration data. Global array?
Upvotes: 4
Views: 7158
Reputation: 12843
I'm gonna swear in church and humbly point out that one can do both :)
You can store the configuration parameters in a database and then produce whatever configuration file you need when the parameters are saved.
This is a form of redundancy, but it also gives the following advantages:
Upvotes: 2
Reputation: 7212
Something like this should work for you:
CREATE TABLE `config` (
`prop` varchar(100) DEFAULT NULL,
`value` mediumtext,
UNIQUE KEY `lookup` (`lookup`)
) ENGINE=InnoDB
Put your keys into prop, and the config values into value.
Upvotes: 0
Reputation: 3920
Your approach is very common for settings that users change through a web interface.
You might look at the way WordPress stores configuration in the database.
Upvotes: 0
Reputation: 63616
Consider the following:
I would generally go for a config file, for small web applications.
Once you get as far as having an infrastructure involving web & non-web servers, putting the config in a centrally-accessible place becomes an advantage though. This doesn't have to be a SQL database, some people use LDAP or even DNS.
Upvotes: 9
Reputation: 799450
One row per, similar to EAV.
Sure, global array or object sounds fine.
Upvotes: 0