How to find out if the last operation was inserted or updated when using insert to duplicate updates in mysql and php?

I use PHP and MySQL.

If I use the INSERT ON DUPLICATE UPDATESQL statement, then how do I know if the last operation was a successful insert, and not an update or a failed insert?

The assumptions in this table do not use auto-increment, so I cannot use mysql_insert_idto help me find out.

+5
source share
1 answer

You will need to check mysql_affected_rows (), which will return 1 on insert and 2 on update. According to mysql documentation .

if (mysql_affected_rows() == 1) //INSERT
elseif (mysql_affected_row() == 2) //UPDATE

, 0.

+8

All Articles