I have found answers all over the place on how to INSERT or UPDATE if record already exists, a good approach is using the on duplicate key update
or REPLACE, but I can't seem to find anywhere how to do this using a prepared statement. Is this possible?
EDIT:
Ok let me be more specific with my question:
If I have a mysqli prepared statement like this example:
if ($stmt = $mysqli->prepare("UPDATE test SET name= ?, age= ? WHERE iduser= ?")) {
$stmt->bind_param('ssi', $name, $age, $id);
$stmt->execute();
}
In this case how can I build a on duplicate key update
This is were Im stuck, I dont know how to use the "?" :
if ($stmt = $mysqli->prepare("INSERT INTO test (iduser, name, age) VALUES (?,?,?))){
ON DUPLICATE KEY UPDATE name=?,age=?")) {
$stmt->bind_param('iss', $id, $name, $age);
$stmt->execute();
}