Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using a database to store configuration rather than a configuration file

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?

like image 278
James Smith Avatar asked Dec 22 '22 20:12

James Smith


1 Answers

Consider the following:

  • SOME configuration will have to be stored in a config file unless you hard code it, notably, how to connect to the database
  • Databases are bad at storing some types of config data - highly structured stuff, or things with unpredictable or variable structure - and you may end up with a schema which doesn't make a lot of sense
  • It is much easier to store config files in a SCM system
  • You can simply replace a config file upon upgrade, you can roll it back if you need to go back. Try doing this with database tables? Even in a best-case scenario, it's harder.

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.

like image 119
MarkR Avatar answered Jan 14 '23 14:01

MarkR