如何在mysql中存储+4000个用户首选项

I really don't know how to set this DB up.

I have a list of 10k users.

Each one needs to have +4000 boolean data.

I'm confused as to how I should store these because I would need to split them in php and work with them often in the pages.

Thanks.

simplest solution (but not the best one) is to store them as long string (varchar/text type) where each symbol corresponds to some boolean value, so you will have something like '010101010101010', note - you should use binary char with ascii encoding

so you will be able to work with these data like $string[$someIndex]

another approach: store it as long bit mask - this will take 8 times less amount of memory (blob type)

3rd variant: store them in table like id_user, id_preference, bitvalue, each row - one preference for one user

4th variant: reconsider your application - there is no sense in 4000+ preferences for each user :)

You can serialize the data and store it in a TEXT in SQL, and then unserialize the data and store it in your $_SESSION

create table user_prefs ( user_id int, prefs varchar(4000));

Each char is a single preference.

in php(or something like this using MDB2):

    $res = $db->query("select * from user_prefs where user_id=$user_id");
    $row = $res->fetchRow();
    $user_prefs = $row[1];
    //now your $user_prefs[i] is the ith preference.