Good practice to store user settings PHP/MySQL

Posted on 2009-12-23
Medium Priority
Last Modified: 2013-12-12
I am currently building (a 1001th) community website. I already build the whole interface with hundreds of lines of CSS. Also the relational MySQL database is also build ready in MySQL Workbench.

I set up a fully working multi-language and ActiveRecord CodeIgniter workspace so I'm read-set to go.

I have one last thing I'm pondering about. The user's preferences storing methodic.

I had something like this in the DB structure:

" pref (VARCHAR(45))
" value (TEXT)

I know the methods to store arrays in the a DB-field etc. but I was wondering how others do it. I want to do it DB-wise.

Now I can achieve things like:
$query = mysql_query("SELECT * FROM user_preferences WHERE users_id == $_SESSION['user_id']");

$result = mysql_fetch_assoc($query);

// Some loop through these 2 values to combine them in a logic result
// After collecting all data storing them in a ordered array or object and store it in the SESSION or something like that

Open in new window

Question by:Erwin_001
  • 2
LVL 11

Accepted Solution

asafadis earned 750 total points
ID: 26118430
Looks fine to me.
I would even dare to say that this is the "industry standard"!

It's the same technique WordPress uses: http://codex.wordpress.org/images/8/83/WP_27_dbsERD.png
Check out the "usermeta" table on the top left.

Author Comment

ID: 26118522
Nice : ).

I'm having community settings like:

show_dateofbirth (yes, no, friends_only)


Guess this is satisfactory enough. I works pretty well until now : ). Was just wondering.


Author Closing Comment

ID: 31669678

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses
Course of the Month17 days, 10 hours left to enroll

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question