我正在尝试使用 php 格式化 mysql insert 语句,sprintf
但这样做会插入 a0
而不是NULL
记录列。我正在寻找解决此问题的方法,同时仍在使用sprintf
格式化:
$query = sprintf("INSERT INTO `efix_lines`
(EventID, Serial, SerialRequired, PartNumber,
MfgRev, DefectID, CircuitReference, CreatorID,
CreatorName, Created)
VALUES (%d, '%s', %d, '%s', '%s', %d, '%s', %d, '%s', '%s')",
$oSubmitData['EventID'],
EVL($oSubmitData['Serial'], NULL),
EVL($oSubmitData['SerialRequired'], NULL),
EVL($oSubmitData['PartNumber'], NULL),
EVL($oSubmitData['MfgRev'], NULL),
EVL($oSubmitData['DefectID'], NULL),
EVL($oSubmitData['CircuitReference'], NULL),
$oSubmitData['CreatorID'],
$oSubmitData['CreatorName'],
$pDate );
//I made this quick EVL function to help with shorthand ternary operators within my actual syntax
function EVL( $var1, $var2 ){
return ( empty( $var1 ) ? $var2 : $var1 );
};
DefectID
尝试插入时出现问题,NULL
因为它是空的。 sprintf
想要插入一个整数作为%d
指示,所以它插入0
而不是NULL
. 我能做些什么?