PHP MySQL INSERT ON DUPLICATE KEY UPDATE不起作用 [英] PHP MySQL INSERT ON DUPLICATE KEY UPDATE not working

查看:301
本文介绍了PHP MySQL INSERT ON DUPLICATE KEY UPDATE不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的查询:

INSERT INTO `table` (`article_id`, `score_count`) VALUES (1922, '{\"1\":3,\"2\":2,\"3\":10,\"4\":2,\"5\":1}') ON DUPLICATE KEY UPDATE `article_id`= 1922

并且我的article_id列设置为主唯一键.运行此命令后,我插入了0行并且没有更新.

And my article_id column is set as primary unique key. After I run this I get 0 rows inserted and no update.

推荐答案

INSERT INTO `table` (`article_id`, `score_count`) 
VALUES (1922, '{\"1\":3,\"2\":2,\"3\":10,\"4\":2,\"5\":1}') 
ON DUPLICATE KEY 
UPDATE `score_count`= '{\"1\":3,\"2\":2,\"3\":10,\"4\":2,\"5\":1}'

因为您不想将主键更新为其自身.

Since you don't want to update the primary key to itself.

ON DUPLICATE KEY UPDATE会将指定的列更新为一个值.您正在将已经是1922article_id更新为1922.参见官方参考.

ON DUPLICATE KEY UPDATE updates the specified column to a value, if a duplicate key was found. You were updating article_id which was already 1922 to 1922. See the offical reference.

这篇关于PHP MySQL INSERT ON DUPLICATE KEY UPDATE不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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