使用insert更新表时出错重复密钥更新时

6l7fqoea  于 2021-06-20  发布在  Mysql
关注(0)|答案(1)|浏览(382)

我对mysql比较陌生。由于某些原因,我的insert on duplicate key update命令出错。它看起来是这样的:

print "Writing status to file \n";
$mysqliNode = new mysqli('blah.net', 'us', 'pw', "CATV_Mon");
$stmtNode = $mysqliNode->prepare("INSERT INTO CATV_Mon.nodeDetail (nodID, pctRedYellow, count)
                                  VALUES (?,?,?) 
                                  ON DUPLICATE KEY UPDATE pctRedYellow   = VALUES(percentRedYellow)
                                                         ,count     = VALUES(count)                               
                                  ");
$index = "ABCF";
$tempCount = 5000; 
$node_percent_down = 55;
$stmtNode->bind_param("sss",$index,$node_percent_down,$tempCount);
if(!$stmtNode->execute) {
        $tempErr = "Error getting Node $nod info and put in table: " . $stmtNode->error;
        printf($tempErr . "\n");    //show mysql execute error if exists  
        $err->logThis($tempErr);
        printf ("will die on purpose now \n");  
        die();          
} //if stmtNode didn't execute ok

当我运行它时,我看到(它没有显示错误消息):

Writing status to file
Error getting Node WILL info and put in table:  
will die on purpose now

我尝试在mysql workbench中使用以下语句:

INSERT INTO CATV_Mon.nodeDetail (nodID, pctRedYellow, count)
                                  VALUES ("ABCE",30,5000) 
                                  ON DUPLICATE KEY UPDATE pctRedYellow   = VALUES(pctRedYellow)
                                                         ,count     = VALUES(count) ;

这是可行的,我在表中看到1行受影响。当我更改值以更新并在workbench中运行它时,它会更新所更改的内容并在表中看起来很好。
你知道php脚本为什么会失败吗?我试着改变我要插入的nodeid,但同样失败了。
表结构是:nodid varchar(20)primary key pctredyellow int(5)count int(8)
我在网上搜索了一下,看起来我在做我该做的事。重复密钥更新时插入。我想我需要在我的语句中的where,但是它在workbench中工作,并且在链接处的语法看起来很好。

vaqhlq81

vaqhlq811#

我找到了这个,它修好了。绑定参数无效
$stmtnode->bind\u param('sii',$index,$node\u percent\u down,$tempcount);

相关问题