dongshi4078 2012-07-12 22:50
浏览 37

知道插入忽略(MySQL)是否实际插入PHP中

Right now I am using Insert Ignore to insert a bunch of tuples into my DB. However, I want to know whether or not the tuple was actually inserted or not and based on that do some action. Code is in PHP:

if(!($stmt4 = $mysqliprivate3->prepare("INSERT IGNORE INTO ".$table." VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"))){
                                echo "Prepare Failed3: (" . $mysqliprivate3->errno . ") " . $mysqliprivate3->error;
                            }
                            else{
                                $stmt4->bind_param("ssisssssssssssss", $id, $dt, $score, $question1, $question2, $question3,$question4,$question5,$question6,$question7,$question8,$question9a,$question9b,$question9c,$question9d,$question9e);
                                $stmt4->execute();
                                $stmt4->close();
                            }
                            //if(inserted){
                                Do something
                            }

I have tried using echo $mysqliprivate3->affected_rows; but it seems to give me a 1 even if it isn't inserting anything. What else could I do?

Thanks,

  • 写回答

1条回答 默认 最新

  • douqing0713 2012-07-12 23:16
    关注

    try this:

    if ($stmt4->affected_rows)
    {
        // ...
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 Oracle触发器记录修改前后的字段值
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器