I’m wondering what best tactic is for saving a large array of user preferences for a website. Mostly things like default values, like default timezone, default text size, etc. Making a separate column for each setting doesn’t sound practical. The only way I can think of currently is to add a singe column in the users table for preferences, and put all the settings in there.
For example, I could use formatting like this in one column only: timezone:GMT;text_size:12;default_value1:something;default_value2:FALSE. Then when grabbing it in PHP, I would select this column for the logged in user and do an explode on the result, setting $_SESSION[‘settings’][‘setting_key’] = “setting_value”.
Is there a smarter way to do this, or am I already in the right direction? The only downside to this is not being able to search through each specific setting, of course, since everything is lumped together.
IMHO that’s what serialize is just perfectly meant for.
If you want it searchable you might want to end up splitting them up.
On the other hand, you might want to take a totally different approach and instead of storing in a large table with setting per column, you can create a table of a kind:
and store settings like that. Then you are not limited by adding/removing columns.
Another approach (to further speed up possible settings lookups) would be to create a multiple of tables:
considering that
setting_idis a foreign key tosettings.idand assuming that you have someuserstable that has user id’s whereuser_idis a foreign key to in both examples.