views:

71

answers:

2

I am modifying my PHP network's code to have "user roles" like wordpress here is my plan so far

0 = registred non email verified user
1 = registed and verified email
2 = moderator
3-9 = nothing yet
10= admin

In my PHP code I will use an array like this that will set what a role number does.

$user_role['10']

I was thinking of storing which value a user has in my mysql DB, would this be the best way to store the 10 different role options as an enum or is there a better way or faster way? I read that enum is not the fastest sometimes.

enum('0','1','2','3','4','5','6','7','8','9','10')
A: 

Use bitmasks for permissions / user levels.

See example.

code_burgar
Care to expand on that answer a little?
ZombieSheep
that looks somewhat complex, you think this would be faster? Also if I used that would I not use enum in mysql?
jasondavis
@jasondavis no you would only store the decimal representation of the permission in the db, read through the changed link in my answer, it explains it really well
code_burgar
thanks, I posted a new question on them
jasondavis
+1  A: 

I guess INT or TINYINT is enough to store user level (role). Also you may consider multiplting the numbers by 10, so you'll have a space to add more levels in future.

pingw33n
i agree with this one. if all you want is a single number to denote user permission, then just use an integer column. if you use ENUM, then the only way you can add new levels is to change your database schema. also, ENUM is mysql specific and non-standard, and in general unless your *really* need a vendor-specific feature, you should avoid them.
longneck