Creating a CMS, I have a “settings” table, in which I store many CMS settings. Such as Site name, URL, etc.
I have seen it where each row is a setting (Vertical)
I have also seen it where each column is a setting (Horizontal)
What do you think the CORRECT method is?
Vertical:
+----------------------+
+id | name | value +
+----------------------+
+0 | site | (url) +
+1 | comments | 0 +
+----------------------+
Horizontal:
+---------------------------------------------+
+id | site | comments | title | etc +
+---------------------------------------------+
+0 | (url) | 0 |YourSite | etc +
+---------------------------------------------+
I personally would use a vertical way of doing it, as it doesn’t restrict you to the settings for which you currently have a column. You can add as many as needed later. With a horizontal approach you’d have to add a new column for each setting.
What Knossos says about caching is true, make sure to cache the settings whenever possible.
Tables like these are read on every pageview and cost database performance while they shouldn’t. Memcached is a very good suggestion but if you only have a single webserver, you can use APC just as well.