title: Catch a foreign key error in php
body: <p>How to catch </p>
  
  <blockquote>
    <p>Cannot delete or update a parent row: a foreign key constraint fails</p>
  </blockquote>
  
  <p>Error</p>
  
  <p>I want to show a message to users that they cannot delete this row when they delete</p>
  
  <pre><code>try
  {
      $success=$db-&gt;query("DELETE FROM tableName WHERE ID=1");                                
  }
  catch (Exception $e) 
  {
       echo "You cannot delete this row";
  }
  </code></pre>