ATTRERRMODE
ATTRERRMODE, commonly written as ATTR_ERRMODE in PHP's PDO extension, is an attribute that controls how errors from database operations are reported. It is represented by the constant PDO::ATTR_ERRMODE and can be set on a PDO instance either in the constructor options or later with setAttribute. The value chosen for this attribute determines how PDO surfaces errors to the application.
- PDO::ERRMODE_SILENT: no error messages or exceptions are raised; error information must be retrieved manually from errorInfo
- PDO::ERRMODE_WARNING: PHP warnings are emitted containing error details.
- PDO::ERRMODE_EXCEPTION: a PDOException is thrown for errors, enabling standard try/catch handling.
ERRMODE_SILENT is the default in many environments, but ERRMODE_EXCEPTION is the most common choice in modern
- $pdo = new PDO($dsn, $user, $pass, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
- $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
Compatibility and implications: most PDO drivers support all three modes, though the exact behavior may vary