Вот обобщенный пример этого использования:
$db->prepare('
INSERT INTO tableName (id, col1, col2, col3...)
VALUES (?,?,?,?)
ON DUPLICATE KEY
UPDATE col1 = VALUES(col1),
col2 = VALUES(col2),
col3 = VALUES(col3)
');
$stmt->bind_param('isss',
$id,
$col1,
$col2,
$col3
);
$db->execute($stmt);
if ($id == null) { //If you need the auto increment from the insert.
$newId = $stmt->insert_id;
}