How can enabling error reporting in PDO help in troubleshooting PHP code?

Enabling error reporting in PDO can help in troubleshooting PHP code by providing detailed error messages when database queries fail. This can help developers quickly identify and fix issues in their code, such as syntax errors or connection problems.

// Enable error reporting in PDO
$pdo = new PDO($dsn, $username, $password);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);