I was taking a tutorial on PDO with PHP and MySQL and noticed I could not generate an exception from this code. I wonder what setting I need to put in place to generate the exception.
If I shut down MySQL I can generate an error but with MySQL running the error is not generated. Below is the error.
SQLSTATE[HY000] [2002] No connection could be made because the target machine actively refused it.
Any ideas of what I should be looking for.
# connect to the database
try {
$DBH = new PDO("mysql:host=$host;dbname=$dbname", $user, $pass);
$DBH->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
# UH-OH! Typed DELECT instead of SELECT!
$DBH->prepare('DELECT * FROM comments');
} catch (PDOException $e) {
echo "I'm sorry, Dave. I'm afraid I can't do that.";
file_put_contents('PDOErrors.txt', $e->getMessage(), FILE_APPEND);
}