after boolean becomes tinyint(1)

Codes here !

Moderators: macek, egami, gesf

yang
New php-forum User
New php-forum User
Posts: 2
Joined: Tue Nov 06, 2012 5:56 am

after boolean becomes tinyint(1)

Postby yang » Tue Nov 06, 2012 6:03 am

hello everyone,
question is: when i create a boolean type column into mysql table, then it will auto change to tinyint(1),

also, in my php function, if $check = true; then the condition ($check == tinyint(1)variable) is valid, but if $check = false, then the condition ($check == tinyint(1)variable) is Invalid!!, but if $check = 0, it wll become valid.

why? and any better suggestion for improve when i facing this situation??~

regards

MeroD
New php-forum User
New php-forum User
Posts: 53
Joined: Wed Oct 10, 2012 12:14 am

Re: after boolean becomes tinyint(1)

Postby MeroD » Wed Nov 07, 2012 3:49 am

BOOLEAN is an alias to TINYINT(1)

Zero is false, anything else is true. Your function will return 0 or 1, which will get transformed into a string--so in PHP you have the strings '0' and '1'... If you need to compare with a zero use ===

seandisanti
php-forum Fan User
php-forum Fan User
Posts: 838
Joined: Mon Oct 01, 2012 12:32 pm

Re: after boolean becomes tinyint(1)

Postby seandisanti » Tue Nov 13, 2012 2:04 pm

you can also use bit for boolean values. it's mostly a matter of preference, but if you have multiple boolean fields, they are stored in a single byte (up to 8 of them) rather than requiring a byte each as with tinyint.


Return to “mySQL & php coding”

Who is online

Users browsing this forum: No registered users and 1 guest

cron