Pablo
Pablo

Reputation: 4313

How do you decide between what you put in your config file and your database

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.

Upvotes: 4

Views: 360

Answers (5)

DOK
DOK

Reputation: 32851

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.

Upvotes: 0

CogitoErgoSum
CogitoErgoSum

Reputation: 2907

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.

Upvotes: 0

wshato
wshato

Reputation: 503

One rule I always use is:

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

Upvotes: 1

Evernoob
Evernoob

Reputation: 5561

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.

Upvotes: 2

Sarfraz
Sarfraz

Reputation: 382806

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.

Upvotes: 1

Related Questions