views:

34

answers:

4

It seams I should use tinyin(); but I dont 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.

Thanks in advance!

Trufa

+1  A: 

You're correct that the general solution is tinyint(1). You can use BOOL for short:

CREATE TABLE example (
         flag BOOL
       );
Matthew Flaschen
+1  A: 

you have option of tinyint(1) or bit

insert 0 or 1 to this field

see this post of the difference :

http://stackoverflow.com/questions/488811/tinyint-vs-bit

Haim Evgi
Thanks for clarification!
Trufa
+1  A: 

Yep, TINYINT(1) is the way to go... you can also use BOOL or BOOLEAN which are synonoums for that (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).

Felix Kling
@Felix Kling Thanks Very useful, already implementing it!
Trufa
+1  A: 

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!

Muktadir