duandao1931 2015-01-27 17:59
浏览 18

在PHP中使用SQL表达式需要帮助

I am trying to omit a column from updating if the value is empty, but would like it to update if its not empty.

So far I came with the following expression

$foo = NULL;


$query = "UPDATE test SET column1 = IF('{$foo}'='',coloumn1,'' )";
$result = mysqli_query($handle,$query);
if(!$result){
    echo mysqli_error($handle);
}

The problem that I am facing is when I set $foo to an actual value coloumn1 is empty again.

I am not sure why. If anyone can help me understand this, I would really appreciate it! Thanks!

  • 写回答

1条回答 默认 最新

  • dongyan2267 2015-01-27 18:04
    关注

    If your value is indeed null (not empty), you might want to consider the use of COALESCE:

    UPDATE test SET column1 = COALESCE(?,column1)
    
    评论

报告相同问题?

悬赏问题

  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)