title: Troubleshooting PDO: Error not caught when executing prepared statement
body: <p>I have run into a problem using PDO because an error was not caught.</p>
  
  <p>The code is simple and works just fine, I'll just include a sample to avoid confusion:</p>
  
  <pre><code>$sql = 'INSERT INTO somedatetable (something) 
          VALUES (:something) 
          ON DUPLICATE KEY UPDATE something=:something';
  
  $values = array(":something" =&gt; $something);
  
  try {
      $stmt = $dbh-&gt;prepare($sql);    
      $stmt-&gt;execute($values);    
  } catch (PDOException $e) {
      echo "Error: " . $e-&gt;getMessage() . "&lt;br /&gt;\n";
  }
  </code></pre>
  
  <p>The code works fine, however when working on a new module, I ran into a problem that no records were added or modified and no error was caught.</p>
  
  <p><code>$stmt</code> returned <code>false</code> but I did not have a clue why or how to find the error.</p>
  
  <p>The solution was simple in the end, I was using a limited MySQL user that did not have write permissions to the table. These errors always displayed right away when using mysql, but using PDO I do not know how to get to them.</p>
  
  <p>How do I get PHP / PDO to display or catch these kind of database errors?</p>