Reputation: 824
1) In my table I have a column that set privileges of the users.
I want have a flag 1/0 (yes/not,true/false and so on..) for my privileges (for example: if the user is admin or mod...).
I searched a lot, I'm still confused about the differences about boolean and bit in terms of resources requests to the DBMS. Which is better?
I also found a lot of question of pasted years, so I'd like to have a fresh answer, in case that something it's changed/improved.
2) Another question...
I tryied to use both of these types and I saw that with boolean, it's easy to check if the value is true or false, but I haven't figured out how to see the value of a variable BIT. I'm my database coloumn I put values 1 or 0, but with a echo of the bit variable, nothing is shown.
So, how can I see the value of a bit (I need to use only 1 or 0).
Thank you in advice!
Upvotes: 3
Views: 1065
Reputation: 1552
Use TINYINT(1)
. It's what's most commonly used for boolean values. Bear in mind though that it allows for values beyond 1 and 0 so for the sake of consistency I'd suggest using the keywords TRUE
and FALSE
when inserting data in it as they reflect 1
and 0
.
BOOL
and BOOLEAN
are just synonyms for TINYINT(1)
. BIT
on the other hand used to be a synonym for TINYINT(1)
before version 5.0.3.
Upvotes: 3