3

This is something that I have been wondering about for a while, and now that I am about to begin another project that requires this, I can't help but wonder if I am doing this the "right way".

Basically, in my API for, in this instance, an enterprise phone system - our client will be able to toggle several options like "forward calls to interactive menu" or modify the spoken greeting that callers hear.

Typically I handle something like this by creating a table in a MySQL database that only has one row that is updated each time the users makes a change to something.

I can't help but feel like this is overkill. Am I doing this the right way?

4

1 回答 1

4

If it's a global setting, that is, not user specific, I'd recommend two tables. One is your list of available settings with their definitions with a SettingID and the other table is just two fields: the foreign key SettingID and what the setting is set to.

If the settings are something that each user can set for themselves, simply add UserID to the second table.

Using two tables like this, so that each new setting is a new row, is more normalized then the way you suggested. It allows you to have your PHP code add settings or modify settings without having to modify your MySQL Database structure.

SettingsList
-----------
SettingID (Auto-increment)
SettingName
SettingDescription

UserSettings
------------
UserID (if using this field, make a compound primary key from SettingID and UserID)
SettingID (SettingsList foreign key, UserSettings primary key if not using UserID)
Setting
于 2013-03-30T22:46:06.570 回答