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 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.