如何将NULL作为变量从PHP发送到SQL?
问题描述:
我想将"NULL"值发送到mySQL中的列.
I want to send a value of "NULL" to a column in mySQL.
$ParentEventID = "NULL";
mysql_query("UPDATE events SET
ParentEventID = '$ParentEventID'");
该列的默认设置为"0".我已将列设置为接受NULL,并且可以使用NULL复选框编辑单元格.
The column keeps defaulting to "0". I have the column set to accept NULL and I can edit the cell with the NULL check box.
我不需要将默认值设置为NULL,因为它可能会影响其他地方的代码.
I need to not set the default to NULL because it may effect code in other places.
答
您在正确的轨道上,使"NULL"
成为字符串.如果需要将其设置为NULL
,则删除$ParentEventID
周围的qoutes.
You are on the right track making "NULL"
a string. If you need to set it NULL
, then remove the qoutes around $ParentEventID
.
mysql_query("UPDATE events SET ParentEventID = $ParentEventID");
但是,在执行此操作之前,请确保$ParentEventID === NULL
的值.
However, before doing so make sure that the value of $ParentEventID === NULL
.