Boolean Field in mysql db Boolean Field in mysql db mysql mysql

Boolean Field in mysql db


In MySQL BOOLEAN type is a synonym for TINYINT. There is no dedicated BOOLEAN type. The vaules accepeted, are those for TINYINT i.e. 0 for false, 1-255 (preferably 1) for true.


MySQL doesn't really have a BOOLEAN type, if you create a BOOLEAN column it will actually be a TINYINT.

Treating TINYINT as a boolean isn't too problematic though, if you treat 0 as false and non-0 as true then it's fine. In PHP a statement like if ($column) will return true if $column is any value except 0 or something that evaluates to 0. If you need it to explicitly be a bool you can convert it easily enough by doing $column = ($column != 0);