我试图将params绑定到INSERT INTO MySQLi预处理语句,如果该变量存在,否则插入null.然后我知道
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时,我如何定义变量的类型?或者我应该定义类型''?
您不需要将null转换为特定的数据类型 - Mysqli将处理传递给任何接受的数据类型的空值,因此只要使用每个字段在传递非空值时所具有的类型.
$intVar = null; $doubleVar = null; $stringVar = null; $blobVar = null; $insert_data->bind_param('idsb', $intVar, $doubleVar, $stringVar, $blobVar);
所有这些都是有效的,并将被Mysqli接受.