Recall & Review
beginner
What is PDO in PHP?
PDO stands for PHP Data Objects. It is a way to connect to databases in PHP using a consistent interface.
Click to reveal answer
beginner
Why use exceptions for error handling with PDO?
Exceptions let you catch errors cleanly and handle them without stopping the whole program abruptly.Click to reveal answer
intermediate
How do you enable exceptions for PDO errors?
Set the PDO attribute PDO::ATTR_ERRMODE to PDO::ERRMODE_EXCEPTION when creating the PDO object.
Click to reveal answer
intermediate
What PHP code snippet shows catching a PDO exception?
try {
// PDO code here
} catch (PDOException $e) {
echo 'Error: ' . $e->getMessage();
}
Click to reveal answer
beginner
What happens if you don't catch a PDO exception?
The script stops running and shows a fatal error message, which is not user-friendly.
Click to reveal answer
How do you tell PDO to throw exceptions on errors?
✗ Incorrect
You must set the error mode attribute to PDO::ERRMODE_EXCEPTION to enable exceptions.
What class do you catch to handle PDO exceptions?
✗ Incorrect
PDO throws exceptions of the class PDOException.
What is the benefit of using try-catch with PDO exceptions?
✗ Incorrect
Try-catch lets you handle errors gracefully without stopping the script.
What method gets the error message from a PDO exception?
✗ Incorrect
getMessage() returns the error message from the exception.
If PDO error mode is not set to exceptions, what is the default behavior?
✗ Incorrect
By default, PDO returns false on errors and does not throw exceptions.
Explain how to set up PDO to use exceptions for error handling and why it is useful.
Think about setting attributes when creating PDO and catching exceptions.
You got /4 concepts.
Describe what happens when a PDO exception is thrown and not caught in your PHP script.
Consider the impact on the program flow and user experience.
You got /4 concepts.