Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the best boolean value for MySQL?

Tags:

mysql

Having issues with the value being returned from MySQL from an AJAX query that selects a check box. But the only way I can get it to work is to have the value in MySQL as NULL.

But 0 or 1 will return it checked every time. In MySQL I have it set to tinyint(1).

like image 327
Mont Avatar asked Dec 21 '25 06:12

Mont


1 Answers

In MySQL boolean is an alias for tinyint(1). I suggest using boolean.
The MySQL writers do things for a reason. I'm sure they have a good reason for choosing tinyint over bit.

You will never get smaller storage requirement than 1 byte.

Make sure you do a check against 1

if $row['bool_field'] == 1 {check that box}
else {uncheck that box}
like image 75
Johan Avatar answered Dec 22 '25 19:12

Johan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!