0

在我的表中,有一个名为 receivedOn 的列,它是一个日期类型。所以如果我这样做

$receivedOn= "2013-11-11";
$stmt = $dbi->prepare("insert into mytable(somedata,receivedOn) values (?,?)");
$stmt->bind_param('ss',$somedata,$receivedOn); 
$result = $stmt->execute() or die (mysqli_error($dbi)");

它会成功插入数据,但如果 $receivedOn 为空,它不会插入数据,看起来就像挂在那里一样。没有返回错误。即使receivedOn为空,如何让mysqli插入数据?我可以使用普通 mysql 查询(非 mysqli)插入带有 emtpy receivedOn 的数据

4

1 回答 1

1

尝试做:

$receivedOn = ($receivedOn != '') ? $receivedOn : NULL;
$stmt = $dbi->prepare("insert into mytable(somedata,receivedOn) values (?,?)");
$stmt->bind_param('ss',$somedata,$receivedOn); 
...
于 2013-10-22T05:15:45.487 回答