Php 在重复键上,更新时将1列设置为零

Php 在重复键上,更新时将1列设置为零,php,mysql,pdo,Php,Mysql,Pdo,我目前正在试验insert ignore。。在mysql中重复密钥更新时..语句。我有以下疑问 在重复密钥更新密码=?年龄=? 我在pdo上有以下绑定: array (size=5) 0 => string 'hello' (length=7) 1 => string 'world' (length=7) 2 => int 24 3 => string 'welcome' (length=7) 4 => int 24 user列是唯一的,但其他

我目前正在试验
insert ignore。。在mysql中重复密钥更新时..
语句。我有以下疑问

在重复密钥更新密码=?年龄=?

我在pdo上有以下绑定:

array (size=5)
  0 => string 'hello' (length=7)
  1 => string 'world' (length=7)
  2 => int 24
  3 => string 'welcome' (length=7)
  4 => int 24
user
列是唯一的,但其他列不是唯一的。还有一个自动递增的
id
字段,它是主键

然而,存在一个问题。每当执行
update
函数时,它都会将密码设置为0(这是不应该发生的)

那么,我做错了什么

注意:我正在使用PDO库

[编辑]:根据注释的代码

$statement = $connection->prepare($sql);
$exec = $statement->execute($bindings);

您在
密码=?年龄=?
替换为

替换:


听起来像是将字符串绑定为某个整数……不过,请使用以下方法:

 INSERT INTO user (user,password,age) VALUES (?,?,?) 
 ON DUPLICATE KEY UPDATE password=VALUES(password), age=VALUES(age);

。。无需再次绑定相同的变量/值。

Ah,捕捉得不错,完全错过了;)
 INSERT INTO user (user,password,age) VALUES (?,?,?) 
 ON DUPLICATE KEY UPDATE password=VALUES(password), age=VALUES(age);