Automattic / HyperDB

HyperDB is an advanced database class that supports replication, failover, load balancing, and partitioning.
105 stars 22 forks source link

Set default mysqli error mode. #41

Closed cfinke closed 2 years ago

cfinke commented 2 years ago

In PHP 8.1, the default error mode for mysqli is set to MYSQLI_REPORT_ERROR|MYSQLI_REPORT_STRICT. This causes errors to raise exceptions rather than be silenced, as explained in https://php.watch/versions/8.1/mysqli-error-mode

The wpdb class already resets this (https://github.com/WordPress/wordpress-develop/blob/5.9/src/wp-includes/wp-db.php#L1724); should HyperDB reset it also?

My assumption is that after $this->use_mysqli = $this->should_use_mysqli(); in __construct(), the following could be added:

if ( $this->use_mysqli ) {
    mysqli_report( MYSQLI_REPORT_OFF );
}

At least for the project I'm using HyperDB on, this fixes the issue with mysqli exceptions being raised and ending scripts.