Reputation: 1951
In PHP, how to detect which one happened (INSERT
or UPDATE
) in the following query:
INSERT INTO ... ON DUPLICATE KEY UPDATE ...
Upvotes: 4
Views: 1500
Reputation: 1951
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.
Upvotes: 9