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

后端 未结 4 990
醉酒成梦
醉酒成梦 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:40

    you could try this without parameter

    if($_POST['bool'] == 1)
    {
     $bool = "b'1'";
    }
    else
    {
     $bool = "b'0'";
    }
    $statement = $pdo->prepare("INSERT INTO `test` (SomeText,TestBool) VALUES (?,$bool)") ;
    $statement->execute(array("TEST")) ;
    

    and no security problem

提交回复
热议问题