Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for WP 6.1.0 + and PHP 8.1+ #18

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions db.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Plugin URI: https://premium.wpmudev.org/project/multi-db/
Description: Allows you to scale your standard Multisite install to allow for millions of blogs and segment your database across multiple physical servers.
Author: WPMU DEV
Version: 4.0
Version: 4.0.1
Author URI: http://premium.wpmudev.org/
WDP ID: 1

Expand Down Expand Up @@ -154,9 +154,17 @@ function add_dc_ip( $ip, $dc ) {

// To allow extending of database class
$wpdb = 'we-need-to-pre-populate-this-variable';
require_once ABSPATH . WPINC . '/wp-db.php';

if ( !defined( 'MULTI_DB_VERSION' ) ) define( 'MULTI_DB_VERSION', '4.0' );
//For WP 6.1+. File wp-db.php is deprecated since WordPress version 6.1.0
//@since 5.0
global $wp_version;
if ( version_compare($wp_version,'6.1.0') >= 0) {
require_once ABSPATH . WPINC . '/class-wpdb.php';
} else {
require_once ABSPATH . WPINC . '/wp-db.php';
}

if ( !defined( 'MULTI_DB_VERSION' ) ) define( 'MULTI_DB_VERSION', '5.0' );
if ( !defined( 'WP_USE_MULTIPLE_DB' ) ) define( 'WP_USE_MULTIPLE_DB', false );
if ( !defined( 'DB_SCALING' ) ) define( 'DB_SCALING', '16' );
if ( !defined( 'EZSQL_VERSION' ) ) define( 'EZSQL_VERSION', 'WP1.25' );
Expand Down Expand Up @@ -364,6 +372,14 @@ public function get_all_tables( $tables ) {
* @return boolean|resource The database connection resource on success, otherwise FALSE.
*/
public function db_connect( $query = 'SELECT 1' ) {
/*
* Set the MySQLi error reporting off because WordPress handles its own.
* This is due to the default value change from `MYSQLI_REPORT_OFF`
* to `MYSQLI_REPORT_ERROR|MYSQLI_REPORT_STRICT` in PHP 8.1.
*@since version 5.0
*/
mysqli_report( MYSQLI_REPORT_OFF );

if ( empty( $query ) ) {
return false;
}
Expand Down