How can I add a Boolean field to MySQL?
It seems I should use tinyint(); but I don't know how to implement it?
The question is what is your recommendation if I need to have a boolean field in MySQL DB and modify it´s value with PHP
Yep, TINYINT(1)
is the way to go... you can also use BOOL
or BOOLEAN
which are synonyms (so it does not make a difference).
0
evaluates to false
in PHP and 1
to true
(actually, any other number than 0
evaluates to true
, but 1
is normally used).
I prefer none of bool, BIT, TINYINT(1). because none of them are actually boolean. You can check the following link for 'why':
http://dev.mysql.com/doc/refman/5.0/en/numeric-type-overview.html
I would better use : ENUM ('false', 'true') not null - as datatype. You can pass 'true' or 'false' (as strings) from PHP. And it will take only 1 byte to store it!
You're correct that the general solution is tinyint(1)
. You can use BOOL for short:
CREATE TABLE example (
flag BOOL
);
链接地址: http://www.djcxy.com/p/25142.html
上一篇: 在MySQL中存储货币值的最佳数据类型
下一篇: 我如何添加一个布尔字段到MySQL?