In PHP, how to detect which one happened (INSERT
or UPDATE
) in the following query:
INSERT INTO ... ON DUPLICATE KEY UPDATE ...
From the PHP manual mysql_affected_rows :
In the case of "INSERT ... ON DUPLICATE KEY UPDATE" queries, the return value will be 1 if an insert was performed, or 2 for an update of an existing row.
So using the function mysql_affected_rows()
after execution of the query, it can be detected from the returned value of the function.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With