这将打印错误代码以及相应的详细消息。
建议:这只是一个示范。只用于调试目的。不要启用在发布版本中向公众显示错误消息。try{connection=$this->get_connection();//here i brought my connection stringconnection->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;