 <p>I had to figure this out one time, so I'm referring to my notes on the matter.</p> <p>The following query:</p> <pre><code>INSERT INTO table ... ON DUPLICATE KEY UPDATE ..., id = LAST_INSERT_ID( id) </code></pre> <p>Where 'id' is the primary key on the table, allows you to call <a href="http://us2.php.net/mysqli_affected_rows" rel="nofollow">mysqli_affected_rows()</a>, which will return:</p> <ol> <li>0 - Row existed, nothing updated</li> <li>1 - No row existed, inserted</li> <li>2 - Row existed, something updated</li> </ol>