Which MySQL Datatype to use for storing boolean values from/to PHP?
Posted
by Beat
on Stack Overflow
See other posts from Stack Overflow
or by Beat
Published on 2008-11-14T10:36:18Z
Indexed on
2010/05/15
22:40 UTC
Read the original article
Hit count: 125
Since MySQL doesn't seem to have any 'boolean' datatype, which datatype do you 'abuse' for storing true/false information in MySQL? Especially in the context of writing and reading from/to a PHP-Script.
Over time I have used and seen several approaches:
- tinyint, varchar fields containing the values 0/1,
- varchar fields containing the strings '0'/'1' or 'true'/'false'
- and finally enum Fields containing the two options 'true'/'false'.
None of the above seems optimal, I tend to prefer the tinyint 0/1 variant, since automatic type conversion in PHP gives me boolean values rather simply.
So which datatype do you use, is there a type designed for boolean values which I have overlooked? Do you see any advantages/disadvantages by using one type or another?
© Stack Overflow or respective owner