Since MySQL doesn't seem to have any 'boolean' data type, which data type do you 'abuse' for storing true/false information in MySQL?
(由于MySQL似乎没有任何“布尔”数据类型,你滥用'哪种数据类型'来存储MySQL中的真/假信息?)
Especially in the context of writing and reading from/to a PHP script.
(特别是在写入和读取PHP脚本的上下文中。)
Over time I have used and seen several approaches:
(随着时间的推移,我使用并看到了几种方法:)
- tinyint, varchar fields containing the values 0/1,
(tinyint,包含值0/1的varchar字段,)
- varchar fields containing the strings '0'/'1' or 'true'/'false'
(包含字符串'0'/'1'或'true'/'false'的varchar字段)
- and finally enum Fields containing the two options 'true'/'false'.
(最后枚举包含两个选项'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. (我更倾向于使用tinyint 0/1变体,因为PHP中的自动类型转换非常简单地给出了布尔值。)
So which data type 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? (您是否看到使用某种类型的优点/缺点?)
ask by translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…