空值被'' [英] Null value is substituted by ''
本文介绍了空值被''的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果$ Time为空,则在查询中它被替换为''。因此查询不正确。如何避免这个问题?
If $Time is null, then in the query it is substituted by ''. As a result the query is incorrect. How to avoid this problem?
$Time = strtotime($arrivals[$i]["time"]);
if ($Time != null)
{
$Time = strftime("%Y-%m-%d %H:%M:%S", $Time);
}
$query="INSERT INTO `Schedule` (`Time`) VALUES('".$Time."');";
结果查询:
INSERT INTO `schedule` (`Time`) VALUES('');
但应该是:
INSERT INTO `schedule` (`Time`) VALUES(null);
推荐答案
如果你想要 NULL
,而不是'2013 -...'
,您显然必须多做一点。
If you want NULL
in the query instead of '2013-...'
, you obviously have to do a little more.
if ($Time === null) {
$Time = 'NULL';
} else {
$Time = strftime("'%Y-%m-%d %H:%M:%S'", $Time);
// ^ note the quotes ^
}
$query = "INSERT INTO `Schedule` (`Time`) VALUES ($Time);";
// note: no quotes ^ ^
这篇关于空值被''的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文