title: Get MySQL error code with PHP
body: <p>I'm using PHP and PDO to connect to my MySQL database. I configured the PDO connection so that I get any MySQL error thrown as an exception:</p>
  
  <pre><code>$dbConnection-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  </code></pre>
  
  <p>Now lets suppose I execute a MySQL command that generates an error and I catch it, the error message is this:</p>
  
  <blockquote>
    <p>SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'Name' cannot be null</p>
  </blockquote>
  
  <p>When I use <code>$exception-&gt;getCode()</code> it returns <code>23000</code>, which I think is from PHP or something. How do I get the specific MySQL error (<code>1048</code>) inside a catch block?</p>