title: MySQL: How do I do ON DUPLICATE KEY UPDATE where two primary keys MUST match?
body: <p>I need to be able to run all of the following within one query call using mysqli->multi_query, which is why this is tricky. I have a table that consists of the following columns:</p>
  
  <ul>
  <li>id</li>
  <li>email</li>
  <li>event_promo_code</li>
  <li>event_id</li>
  </ul>
  
  <p>When the script is run, I need to be able to insert new rows or UPDATE a row if both the <code>id</code> AND <code>event_id</code> match an existing record (not just one key or the other).</p>
  
  <p>What I have now is:</p>
  
  <pre><code>INSERT INTO `rsvps` 
  SET id='$rsvpID', email='$rsvpEmail', 
        event_promo_code='$rsvpEventCode', event_id='$eventID' 
  ON DUPLICATE KEY UPDATE id='$rsvpID', 
        email='$rsvpEmail', event_promo_code='$rsvpEventCode', event_id='$eventID';
  </code></pre>
  
  <p><code>id</code> is my primary key. If I also set <code>event_id</code> as a key, it does an update when either id matches a record or event matches a record, but doesn't check to see if BOTH match at the same time before it updates.</p>