开发者

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 f开发者_JAVA百科ile 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.


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.


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.


One rule I always use is:

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


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜