try {
$dbh = new PDO(
"mysql:host=$db_host;dbname=$db_name",
$db_user,$db_pass,
array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION)
);
$dbh->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ);
$dbh->exec("SET NAMES utf8");
$error_array = $dbh->errorInfo();
if($dbh->errorCode() != 0000) {
echo "Ошибка в SQL запросе: ".$error_array;
}
} catch(PDOException $e) {
echo $e->errorMessage();
}