简体   繁体   中英

Boolean save as tinyint(1) in mysql

I made table with some Boolean fields.

CREATE TABLE PM_ADMIN_LIST(
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
username VARCHAR(250) NOT NULL,
password VARCHAR(250) NOT NULL,
mail VARCHAR(250) NOT NULL,
added_time INT,
super_admin VARCHAR(250) NOT NULL,
last_time INT,
last_ip VARCHAR(250),
see_user_per BOOLEAN DEFAULT FALSE,
change_user_per BOOLEAN DEFAULT FALSE,
see_people_per BOOLEAN DEFAULT FALSE,
change_people_per BOOLEAN DEFAULT FALSE,
add_people_per BOOLEAN DEFAULT FALSE,
remove_people_per BOOLEAN DEFAULT FALSE,
see_album_per BOOLEAN DEFAULT FALSE,
add_album_per BOOLEAN DEFAULT FALSE,
change_album_per BOOLEAN DEFAULT FALSE,
remove_album_per BOOLEAN DEFAULT FALSE,
see_music_per BOOLEAN DEFAULT FALSE,
add_music_per BOOLEAN DEFAULT FALSE,
change_music_per BOOLEAN DEFAULT FALSE,
remove_music_per BOOLEAN DEFAULT FALSE,
admin_per BOOLEAN DEFAULT FALSE,
yahoo_per BOOLEAN DEFAULT FALSE,
status_per BOOLEAN DEFAULT FALSE,
pm_per BOOLEAN DEFAULT FALSE,
ip_blocking_per BOOLEAN DEFAULT FALSE
);

But when I check it in phpmyadmin, BOOLEAN fields are tinyint(1) and they are 0 by default. I can make 1 to be TRUE . But when I use === in my PHP code, they can't be converted. (I should use == in if , for , while and I think it can make some bug in my system.)

So, how should I solve it? How should I get it BOOLEAN by default from mysql?

You usually don't get anything but strings in PHP when fetching data from the database. The types are solely used on the database side.

The field is a TINYINT because MySQL doesn't contain a BOOLEAN field at all.

There is no 'boolean' type in MySQL. You could just use the == check in PHP.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM