4

In PHP, how to detect which one happened (INSERT or UPDATE) in the following query:

INSERT INTO ... ON DUPLICATE KEY UPDATE ...
Aliweb
  • 1,891
  • 3
  • 21
  • 44

1 Answers1

9

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.

Aliweb
  • 1,891
  • 3
  • 21
  • 44