I'm using this code to update my ebay auctions based on the auction id. This works fine but occasionally it trys to update an auction that is not in my table. I want to make it so if the auction isn't there then insert it. What is a good way to find out if the auction id isn't in the table?
a) Check using another query prior to running the update if the row exists, using count(`id`) or whatever.
b) Attempt to run the update, then confirm that records were updated using mysql_affected_rows()
c) A clever use of the INSERT ON DUPLICATE KEY UPDATE syntax could potentially do this all in a single query
Look at the number of affected rows? Note that rows where the new values match the existing values of the record will generally not show in affected row information.
What many systems do is attempt to insert. When an error flags based on some unique identifier matching an existing identifier, the application will attempt to update.