我试图在mysql插入查询中使用不同的变量。我对所有字符串变量都没有问题,但是当我为NULL时,我无法实现工作的双变量。
$TemperatureMaxC = NULL;
if (array_key_exists('temperaturemaxc', $component_data))
{
if ((string)$component_data["temperaturemaxc"] != '') {
$TemperatureMaxC = "'".(string)$component_data["temperaturemaxc"]."'";
}
}
$TemperatureMaxC_cast = ($TemperatureMaxC == NULL ? NULL : $TemperatureMaxC);
$query = $this->db->query("INSERT INTO `Components`
(`ManufacturerName`
,`ManufacturerPN`
,`IsDesignPart`
,`DesignPartID`
,`Published`
,`Author`
,`InternalStock`
,`LastModified`
,`TemperatureMaxC`)
VALUES
(".$ManufacturerName."
,".$ManufacturerPN."
,1
,(SELECT `DesignPartID`
FROM `DesignToManufacturingReference`
WHERE (`Part Number` = ".$PartNumber." AND `Value1` = ".$Value1." AND `Value2` = ".$Value2." ))
,".$Published."
,".$Author."
,".$InternalStock."
,".$LastModified."
,".$TemperatureMaxC_cast."
)");
我在$ TemperatureMaxC_cast为NULL时编写了不同的查询?
提前谢谢你:)