views:

73

answers:

5

Does anyone have a good system for deciding what to put in the database and what to put in the config file.

My config file is a php array and I have a mysql database.

If for example I have a data set of 5 'rows' that will rarely change (if ever) is it better to keep it in the config file?

I am looking for a rule that I can follow that will help me choose - if anyone has one.

+1  A: 

For config file put anything that could possibly be modified by the developr/user of your project/framework. Generally, it is storing site wide variables and constants.

Use database for things that need not to be modified by users of your framework for example.

Sarfraz
+2  A: 

It really depends on the data. The config file is really used for application specific settings, whereas your DB should contain the data that your app will use to serve its purpose.

Evernoob
+1: Config == application-specific; database == application-independent.
S.Lott
+1  A: 

One rule I always use is:

If a user (including admin role) will ever need to change it, put it in the database.

wshato
A: 

This is more of a preference question than anything else.

I go more with the rule of if the configuration information is static (relatively) or rarely changing then stick it in a flat file in a secure area to include it from.

For varying configuration options that may change or may require variable place holders then I'd store them into a database.

Using your example of 5 'rows'. I'd stick to a flat file.

CogitoErgoSum
A: 

Sometimes the decision rests on which resource you will have access to change in production. Depending on the size and complexity of your organization, getting a change made in a production config file can require umpteen levels of management approval, and hours (if not days) of delays. While changing the prod database (though a purpose-built app) can be relatively easy.

That special database app might also be helpful for allowing users (or admin users) to change the data.

Another consideration is whether you want the app to restart when the data changes. Sometimes, changing a config file can force a restart -- depends on the web server, etc. If you want to be able to change on the fly, without restarting the app, the database is the place to store the data.

DOK