patternsqlMinor
Database-backed website configuration
Viewed 0 times
databasewebsiteconfigurationbacked
Problem
I'm planning on adding storage for configuration options to the website I'm working on (php + MySQL).
The problem is that I cannot decide between having a 2-column table (with
It seems like using the single row format is superior, because each field can have the proper data type (
At the same time, though, it seems like having a key-value table would possibly be a performance issue since you'd have to fetch all rows to get the full configuration, as well as updating having to find and seek the proper row to update; you also don't get actual typing (and would have to rely on
I'm not planning on having a lot of configuration options (maybe 20 at the most, more likely 5-10), so I'm not sure if key-value or multi-field is the way to go, here.
The problem is that I cannot decide between having a 2-column table (with
key and value fields) that contains multiple rows, one for each option; or an n-column table with one row.It seems like using the single row format is superior, because each field can have the proper data type (
INT, VARCHAR, etc.) and would make fetching all configuration values easier (single-row), but adding a new option would mean a new field every time.At the same time, though, it seems like having a key-value table would possibly be a performance issue since you'd have to fetch all rows to get the full configuration, as well as updating having to find and seek the proper row to update; you also don't get actual typing (and would have to rely on
VARCHAR or TEXT only).I'm not planning on having a lot of configuration options (maybe 20 at the most, more likely 5-10), so I'm not sure if key-value or multi-field is the way to go, here.
Solution
I did this with a project recently, only I had even fewer settings to store. I opted for using a two column table, with each setting being it's own row.
I think there are pluses and minuses to each, but if you're dealing with such a small set of configuration options, there is not going to be a huge performance hit. To put into perspective, phpBB's config table has almost 270 rows of config options.
I think there are pluses and minuses to each, but if you're dealing with such a small set of configuration options, there is not going to be a huge performance hit. To put into perspective, phpBB's config table has almost 270 rows of config options.
Context
StackExchange Database Administrators Q#8046, answer score: 3
Revisions (0)
No revisions yet.