$database -> errorInfo()[0] # SQLSTATE error code (a five characters alphanumeric identifier defined in the ANSI SQL standard).
$database -> errorInfo()[1] # Driver-specific error code.
$database -> errorInfo()[2] # Driver-specific error message.
try{
//your pdo query here
}
catch(PDOException $e) {
echo json_encode(array('Error'=>$e->getMessage()));
}
// very simple explination .
try{
codeA... }
catch(EXCEPTION $ex){
codeB....
}
//the code in the block Catch excuted if there is an erro in the codeA in the block TRY