WackoWiki: DB driver: Error Mode

https://wackowiki.org/doc     Version: 34 (24.12.2021 03:52)

DB driver: Error Mode

default error mode setting for DB driver:
const DB_ERROR_MODE	= 0;		// DB error mode: 0 - silent, 1 - warning, 2 - exception	

1. MySQLi


As of PHP 8.1.0, the default setting is MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT. Previously, it was MYSQLI_REPORT_OFF.

In other words MYSQLI_REPORT_STRICT will cause a FATAL ERROR for a missing table, field or syntax error. Who wants this in an production environment by default - I don't get it.

Sets mysqli error reporting mode.
Name Description
MYSQLI_REPORT_OFF Turns reporting off
MYSQLI_REPORT_ERROR Report errors from mysqli function calls
MYSQLI_REPORT_STRICT Throw mysqli_sql_exception for errors instead of warnings
MYSQLI_REPORT_INDEX Report if no index or bad index was used in a query
MYSQLI_REPORT_ALL Set all options (report all)

Add option to turn reporting off by default.


= match (DB_ERROR_MODE)


Setting the MySQLi error reporting to off avoids fatal errors due to uncaught exceptions and maintains the current behavior.

2. PDO


PDO::ATTR_ERRMODE: This attribute is used for error reporting. It can have one of the following values.
Name Description
PDO::ERRMODE_SILENT If the ATTR_ERRMODE is not set in the code, ERRMODE_SILENT is the default value of ATTR_ERRMODE attribute. It sets error codes. In silent mode, if there is an error in SQL, PDO will throw no exceptions; PDO will issue no warnings; it will simply return false. Value of PDO::ERRMODE_SILENT is 0. The script will run without generating any error or warning.
PDO::ERRMODE_WARNING This value raises E_WARNING. In warning mode, if there is an error in SQL, PDO will issue warnings but script will continue running. Value of PDO::ERRMODE_WARNING is 1. The script will run with generating warning about the error.
PDO::ERRMODE_EXCEPTION This value throws exceptions. In exception mode, if there is an error in SQL, PDO will throw exceptions and script will stop running. Value of PDO::ERRMODE_EXCEPTION is 2. The script will stop executing generating the error which throws the exception.


= match (DB_ERROR_MODE)

$this->dblink = new PDO($dsn$config->db_user$config->db_password$options);
catch (
PDOException $e)
'PDO DSN Error: ' $e->getMessage());