using nulls in a mysqli prepared statement

后端 未结 5 2216
谎友^
谎友^ 2020-11-29 10:09

In a mysqli prepared statement, a NULL gets turned into \'\' (in the case of a string) or 0 (in the case of an integer). I would like to store it as a true NULL. Is there a

5条回答
  •  借酒劲吻你
    2020-11-29 10:50

    query("CREATE TABLE test_NULL (id int(11))");
    if($query=$mysqli->prepare("insert into test_NULL VALUES(?)")){
        $query->bind_param('i',$null); //note that $null is undefined
        $query->execute();
    }else{
        echo __LINE__.' '.$mysqli->error;
    }
    ?>
    

提交回复
热议问题