What is the type of NULL in mysqli bind_param?

本小妞迷上赌 提交于 2019-12-08 17:45:40

问题


I am trying to bind params to a INSERT INTO MySQLi prepared statement if that variable exists, otherwise insert null.Then i know

type    variable
i   corresponding variable has type integer
d   corresponding variable has type double
s   corresponding variable has type string
b   corresponding variable is a blob and will be sent in packets

but when i insert a variable = null,how i define the type of the variable? Or should i define the type is ''?


回答1:


You do not need to cast null to a particular data type - Mysqli will handle null values passed to any of the accepted data types, so just use the type each field would have had if you were passing non-null values.

$intVar = null;
$doubleVar = null;
$stringVar = null;
$blobVar = null;

$insert_data->bind_param('idsb', $intVar, $doubleVar, $stringVar, $blobVar);

All of these are valid and will be accepted by Mysqli.




回答2:


Set your Variable as null and pass it,

$var1 = null;


来源:https://stackoverflow.com/questions/20963164/what-is-the-type-of-null-in-mysqli-bind-param

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!