我有一个表user_passwords:
user_password_id AI PK
hashPass varchacr(255)
当用户重设密码时,我想更新该行,所以应该这样做,但确实失败了:
insert into user_passwords (user_password_id,hashedPassword)
VALUES('2','$2y$11$pVYR/0hcgOewMn2jgrGx.uGcky5TXxYOPvsbWGyH3VQxZlj3c1QD.')
Error Code: 1062. Duplicate entry '2' for key 'PRIMARY'
我知道,因此我正在尝试以下操作,但没有行得到更新:
insert into user_passwords (user_password_id,hashedPassword)
VALUES('2','$2y$11$pVYR/0hcgOewMn2jgrGx.uGcky5TXxYOPvsbWGyH3VQxZlj3c1QD.')
on duplicate key update hashedPassword=hashedPassword
这是为什么?
您正在寻找这个:
on duplicate key update hashedPassword = VALUES(hashedPassword)
另请参阅以下文档:http : //dev.mysql.com/doc/refman/5.1/zh-CN/insert-on-duplicate.html
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句