I do not think this is possible with just one request. I would go for the INSERT INTO..ON DUPLICATE approach.
$dbQuery = "INSERT INTO UserTable (Id,Age) VALUES('3','25') ON DUPLICATE KEY UPDATE Id='3',Age='25'"; $result = mysql_query($dbQuery); if ($result === FALSE) { // Take care of error } else { $numAffectedRows = mysql_affected_rows(); // $numAffectedRows = 0 => row exist // $numAffectedRows = >0 => row added with Id,Age specified }
user1299518
source share