$ETA_time = strtotime($arrivals[$i]["operationalTimes"]["estimatedGateArrival"]["dateLocal"]);
if (!$ETA_time) {
$ETA = 'NULL';
} else {
$ETA = strftime("%Y-%m-%d %H:%M:%S", $ETA_time);
}
$STA_time = strtotime($arrivals[$i]["operationalTimes"]["scheduledGateArrival"]["dateLocal"]);
if (!$STA_time) {
$STA = 'NULL';
} else {
$STA = strftime("%Y-%m-%d %H:%M:%S", $STA_time);
}
$ATA_time = strtotime($arrivals[$i]["operationalTimes"]["actualGateArrival"]["dateLocal"]);
if (!$ATA_time) {
$ATA = 'NULL';
} else {
$ATA = strftime("%Y-%m-%d %H:%M:%S", $ATA_time);
}
$query="INSERT INTO `Schedule` (`ETA`,`STA`,`ATA`)
VALUES('".$ETA."','".$STA."','".$ATA."');";
$result=run_query($query);
相关的 MySQL DB 表:
CREATE TABLE `Schedule` (
`id` smallint(6) NOT NULL AUTO_INCREMENT,
`STA` datetime DEFAULT NULL,
`ETA` datetime DEFAULT NULL,
`ATA` datetime DEFAULT NULL,
);
查询 var_dump:
INSERT INTO `Schedule` (`ETA`,`STA`,`ATA`) VALUES('2013-08-28 12:30:00','NULL','NULL');
错误信息是:
Incorrect datetime value: 'NULL' for column 'STA' at row 1