问题描述
我正在尝试将参数绑定到INSERT INTO MySQLi准备好的语句中(如果该变量存在),否则插入null.然后我知道
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
但是当我插入一个变量= null时,如何定义变量的类型?还是我应该定义类型为"?
but when i insert a variable = null,how i define the type of the variable? Or should i define the type is ''?
推荐答案
您不需要将null强制转换为特定的数据类型-Mysqli将处理传递给任何可接受的数据类型的null值,因此只需使用每种类型如果您要传递非null值,则该字段将具有.
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);
所有这些都是有效的,并且将被Mysqli接受.
All of these are valid and will be accepted by Mysqli.
这篇关于mysqli bind_param中的NULL类型是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!