This will print error code as well its corresponding detailed message.
Advice: this is just a demonstration. Just use for debugging purpose. Don't enable to show error messages to the public in a release version.
try{
connection=$this->get_connection();//here i brought my connection string
connection->setAttribute(PDO::ATTR_EMULATE_PREPARES,false);
connection->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
/**
Do your works here..
//$statement=$connection->prepare($sql);
//if you are using errorInfo use after prepare statement before execute.here in this method i am not using it.
//print_r($statement->errorInfo());
**/
$statement->execute();
}
catch(PDOException $e) {
//this will echo error code with detail
//example: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'nasme' in 'field list'
echo $e->getMessage();
}
//$statement=null;