【发布时间】:2012-02-17 00:33:00
【问题描述】:
我的表有两列 - col1 (int, null) 和 col2 (int, null) 我希望能够使用空值或 null 语句进行更新。
我的代码如下:
$newkeylimit = $allkeylimits[$row['Group_ID']];
if($newkeylimit == ''){ $newkeylimit = NULL ; }
$newproflimit = $allproflimits[$row['Group_ID']];
if($newproflimit == ''){ $newproflimit = NULL ; }
$sql = "UPDATE ".$mssql_table_prefix."Groups SET Group_Name = '".$newgroupname."', col1 = '".$newkeylimit."', col2 = '".$newproflimit."' WHERE Group_ID = '".$row['Group_ID']."'";
$result = mssql_query($sql)
or die( "<strong>ERROR: Group update query failed</strong>" );
代码执行后,我在假设为空值或 NULL 的每一列中得到 0。 col1 和 col2 的默认值设置为 NULL。
知道我做错了什么吗?谢谢
【问题讨论】:
-
好的,我已将上面的代码更改为:if(empty($newkeylimit) && empty($newproflimit)){ $sqlup = "UPDATE ".$mssql_table_prefix."Groups SET Group_Name = '"。 $newgroupname."', col1 = null, col2 = null WHERE Group_ID = '".$row['Group_ID']."'"; } else { $sqlup = "UPDATE ".$mssql_table_prefix."Groups SET Group_Name = '".$newgroupname."', col1 = '".$newkeylimit."', col2 = '".$newproflimit."' WHERE Group_ID = '".$row['Group_ID']."'"; } 并且它以某种方式起作用。
标签: php sql sql-server-2008 tsql