title: Detect mysql update/insertion failure due to violated unique constraint
body: <p>This is kind of similar to this question:</p>
  
  <p><a href="https://stackoverflow.com/questions/2756186/php-mysql-insert-fails-due-to-unique-constraint">PHP MySQL INSERT fails due to unique constraint</a></p>
  
  <p>but I have a different twist.  Let's say I have a table with only one column.  The column's name is "title" and it has a unique constraint placed on it.</p>
  
  <p>First I insert a row where title = "something".  The next time I try to insert "something" it will fail due to a unique key constraint (which is good).  What I'd like to do is allow it to fail, and check the error code provided by mysql to ensure it failed due to a unique key constraint.  (i.e. let the database handle the uniqueness, and I just handle the error code and tell the user that title already exists when the result comes back).</p>
  
  <p>Is there a way to do this?    </p>