Chris Laplante
Chris Laplante

Reputation: 29658

Is an application-wide "settings table" a good idea?

Wordpress, for example, has a table with name => value rows for storing application-wide settings (the name of the blog, comments settings, etc.). Please note that I'm referring to settings that may be modified often during normal use of the application.

I understand why Wordpress does it like that (portability: it's easy to copy the entire database to another blog and retain settings), but is there a better way to do it for smaller applications?

I know that many frameworks, like Zend Framework for example, have a configuration file with application-wide configuration settings. Why not just dynamically modify that file at runtime to save my settings? To me, this has several advantages over database settings storage:

On the other hand, the biggest complication I can think of is that of concurrency. The file will need to be locked while changes are being made.

What is the preferred way?

Upvotes: 1

Views: 139

Answers (1)

Tomasz Nurkiewicz
Tomasz Nurkiewicz

Reputation: 340723

DB table advantages

  • Settings are global to all web servers sharing the same database. No need for file replication/network file system
  • The application most likely already uses database, no extra setup
  • No dependencies on file system
  • Easier to cache (maybe there is already some generic DB caching layer?)
  • Handles concurrency
  • The application may already have a framework or a way to handle CRUD of any database table (creating GUI is easy)
  • Transparent backup with the rest of your application
  • Can be strongly typed if you have several value columns of different types used exclusively

...and disadvantages

  • you need a tool or SQL knowledge to maintain it
  • might have a worse performance

Upvotes: 1

Related Questions