why PHP casting MySQL BIT(1) value b'0' to boolean 'true' -
i have table in mysql structure followed:
+-------+------------------+------+-----+---------+----------------+ | field | type | null | key | default | | +-------+------------------+------+-----+---------+----------------+ | id | int(10) unsigned | no | pri | null | auto_increment | | name | varchar(32) | yes | | null | | | bit | bit(1) | no | | b'0' | | +-------+------------------+------+-----+---------+----------------+
i insert record followed:
+----+-------------+-----+ | id | name | bit | +----+-------------+-----+ | 1 | john | | +----+-------------+-----+
then use php script select , script followed:
$pdo = new pdo("mysql:host=127.0.0.1;port=3306;dbname=test", "username","password"); $sql = "select * `for_test` `name` = :name"; $stmt = $pdo->prepare($sql); $stmt->execute([':name' => 'john']); while($row = $stmt->fetch(pdo::fetch_assoc)) { var_dump((boolean)$row['bit']); }
i expect output should
bool(false)
however, output
bool(true)
why bit 0 casting 'true'?
Comments
Post a Comment