tags:

views:

437

answers:

1

Using PDO / PHP and MySQL, how can I check if a record was inserted or updated when I use an INSERT ON DUPLICATE KEY UPDATE statement?

I have seen a solution using mysql_affected_rows() for PHP, but I am looking for a way I can use with PDO.

+3  A: 

If you use PDO::exec() the return value will be 1 if the row has been inserted and 2 if the row has been updated.
If you're using a prepared statement and PDOStatement::execute() the same is true for PDOStement::rowCount()

VolkerK
Thanks, I'll give that a try.
jeroen
Great, the execute() one was just what I needed, thanks!
jeroen