using nulls in a mysqli prepared statement

后端 未结 5 2214
谎友^
谎友^ 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:56

    For anyone coming looking at this because they are having problems binding NULL in their WHERE statement, the solution is this:

    There is a mysql NULL safe operator that must be used:

    <=>

    Example:

    prepare("SELECT id FROM product WHERE price <=> ?"); // Will select products where the price is null
    $stmt->bind_param($price);
    ?>
    

提交回复
热议问题