PDOstatement (MySQL): inserting value 0 into a bit(1) field results in 1 written in table

后端 未结 4 988
醉酒成梦
醉酒成梦 2020-11-30 05:47

I\'m using a bit(1) field to store boolean values and writing into the table using PDO prepared statements.

This is the test table:

CREATE TABLE IF N         


        
4条回答
  •  渐次进展
    2020-11-30 06:23

    Because prepare adds ' to your parameter, You have only to add b before parameter name

    $statement = $pdo->prepare('INSERT INTO `test` (SomeText,TestBool) VALUES (?, b?)');
    $statement->execute(array("TEST", 1 /* or TRUE */));
    

    Note: you can use 1, 0 or TRUE, FALSE.

提交回复
热议问题