# Example: `PDO_MySQL` Exception Handling
```
  try {
    ...
  } catch (~!@PDOException $ex@!~) {
    echo "SQLSTATE from PDOException: " . ~!@$ex->getCode()@!~ . "<p>";
    echo "ERRORCODE from Database Handle: " . ~!@$dbHandle->errorInfo()[1]@!~ . "<p>";
    if ($stmt != NULL) {
      echo "ERRORCODE from Statement Handle: " . ~!@$stmt->errorInfo()[1]@!~ . "<p>";
    }
    echo "Error Message from PDOException: " . ~!@$ex->getMessage()@!~ . "<p>";
  }

...

SQLSTATE from PDOException: ~!@42000@!~
ERRORCODE from Database Handle:
ERRORCODE from Statement Handle: ~!@1064@!~
Error Message from PDOException: ~!@SQLSTATE[42000]@!~: Syntax error or access violation: 1064 You have an error 
in your SQL syntax; check the manual that corresponds to your TiDB version for the right syntax to use line 1 column 5 
near "INSER INTO t_php (name, buffered_by_default) VALUES ('mysqli', 'Y')"
```
-------------------------------------------------------------
For example, wrong syntax for the `INSERT` statement:
```
<html>

<body>
  <h1>201.4-PHP Handling Exception 16</h1>
  <?php
  echo "PDO_MySQL Example - Handling Exception" . "<p>";

  try {
    $dsName = "mysql:host=127.0.0.1;port=4000;dbname=test";
    $stmt = NULL;
    $dbHandle = new PDO($dsName, "root", "");
    print "Connection established.<p>";
    $dbHandle->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $dbHandle->exec("DROP TABLE IF EXISTS t_php");
    $dbHandle->exec("CREATE TABLE t_php (id BIGINT PRIMARY KEY AUTO_RANDOM, name VARCHAR(20), buffered_by_default char(1))");

    $sqlStmt = "INSER INTO t_php (name, buffered_by_default)"
      . " VALUES"
      . " (:name, :bbd)";
    $stmt = $dbHandle->prepare($sqlStmt);

    $stmt->bindParam(':name', $name);
    $stmt->bindParam(':bbd', $bbd);

    $name = "mysqli";
    $bbd = "Y";
    $stmt->execute();

    $name = "PDO_MySQL";
    $bbd = "N";
    $stmt->execute();

    $stmt->closeCursor();

    $dbHandle->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true);
    $cursor = $dbHandle->query("SELECT name, buffered_by_default FROM t_php");
    while ($row = $cursor->fetch(PDO::FETCH_ASSOC)) {
      print_r($row);
      echo "<p>";
    }
    $cursor->closeCursor();

    print "End.";
  } catch (PDOException $ex) {
    echo "SQLSTATE from PDOException: " . $ex->getCode() . "<p>";
    echo "ERRORCODE from Database Handle: " . $dbHandle->errorInfo()[1] . "<p>";
    if ($stmt != NULL) {
      echo "ERRORCODE from Statement Handle: " . $stmt->errorInfo()[1] . "<p>";
    }
    echo "Error Message from PDOException: " . $ex->getMessage() . "<p>";
  }

  ?>

</body>

</html>
```