如何将NULL作为变量从PHP发送到SQL? [英] How do you send NULL as a variable from PHP to SQL?

查看:89
本文介绍了如何将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.

这篇关于如何将NULL作为变量从PHP发送到SQL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆