I have some code
$query = 'INSERT INTO table
(foo, bar, baz)
VALUES
(:foo, :bar, :baz)
ON DUPLICATE KEY UPDATE foo = :foo,
bar = :bar,
baz = :baz';
$stmt = $dbc->prepare($query);
$stmt->bindValue(':foo', $foo, PDO::PARAM_STR);
$stmt->bindValue(':bar', $bar, PDO::PARAM_STR);
$stmt->bindValue(':baz', $baz, PDO::PARAM_STR);
$stmt->execute();
Its throwing an error:
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens
Obviously, I have twice as many token as bound variables, but I have the same number of unique tokens. So my question is, can each token only be used once? Will I need to rename the second instance of each token to get it to work, or is there a way to do it without doubling my bindValue
statements?