How can the design of a PHP application utilizing PDO be optimized for better functionality and error handling?

Issue: The design of a PHP application utilizing PDO can be optimized for better functionality and error handling by implementing proper error handling mechanisms such as try-catch blocks to catch exceptions and handle errors gracefully.

try {
    $pdo = new PDO("mysql:host=localhost;dbname=mydatabase", "username", "password");
    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
    echo "Connection failed: " . $e->getMessage();
}