I have MySQL table that doesn’t have AUTO_INCREMENT field. In PHP I run this simple query:
mysql_query("INSERT INTO table ... ON DUPLICATE KEY UPDATE ....");
I need to be able to detect if a new row was inserted into table or if an old row was updated ? Is it possible somehow ?
mysql_affected_rows()returns 1 on an insert (because it inserted one row) and 2 on an update (because first it tried to insert, and then it updated, or something like that).That is when you’re just trying to add one row. You can have the
ON DUPLICATE KEY UPDATEclause on multi-row inserts too, and then you’ll get the sum of 1’s and 2’s for all the rows.