SQL位类型与PHP条件

Today I run into one bug. I have few columns in my DB with BIT type. I am getting those values (0/1) And when I tried to compare it in short if statement I got always false.

$cat->is_visible = ($cat_vis == 1) ? TRUE : FALSE;

This result in FALSE even when the $cat_vis got 1 in DB. Any ideas why is it so ?

I think you'll have issues trying to compare the BIT type directly. What happens if you cast the field in the query?

e.g.

SELECT `is_visible`+0 AS is_visible FROM cat;

or

SELECT CAST(`is_visible` AS UNSIGNED) AS is_visible FROM cat;

Bit are referred with b'1' or 'true/false' or binary notation.Try query using bit notation

SELECT cols FROM tablename WHERE bit_column = (1)

then refer it.

Try this:

$cat->is_visible = ($cat_vis === '1') ? true : false;