title: Insert into MySQL table, overwrite on duplicate
body: <p>I need MySQL to only <code>INSERT</code> a value if the <code>order_id</code> does not exist in the database, so that duplicate rows are not inserted. If the <code>order_id</code> is found, I need the existing data fields to be overwritten. <code>order_id</code> should be unique in all instances.</p>
  
  <p>What's the best way to achieve this?</p>
  
  <pre><code>$statement = $db-&gt;prepare("INSERT INTO carts VALUES(:order_id, :items, :shipping,   :price)");
  $params = array(
    ':order_id' =&gt; $_SESSION['order_id'],
    ':items'    =&gt; Array(),
    ':shipping' =&gt; '0',
    ':price'    =&gt; '0'
  );
  if($statement-&gt;execute($params)) {
    return true;
  }
  else
  {
    return false;
  } 
  </code></pre>