Make WordPress Core

#56484 closed enhancement (fixed)

Site Health: Use $wpdb->db_server_info() to retrieve database server type

Reported by: sergeybiryukov's profile SergeyBiryukov Owned by: sergeybiryukov's profile SergeyBiryukov
Milestone: 6.1 Priority: normal
Severity: normal Version:
Component: Site Health Keywords: has-patch commit
Focuses: Cc:

Description (last modified by SergeyBiryukov)

WP_Site_Health::prepare_sql_data() has this fragment, introduced in [44986] / #46573:

if ( $wpdb->use_mysqli ) {
	// phpcs:ignore WordPress.DB.RestrictedFunctions.mysql_mysqli_get_server_info
	$mysql_server_type = mysqli_get_server_info( $wpdb->dbh );
} else {
	// phpcs:ignore WordPress.DB.RestrictedFunctions.mysql_mysql_get_server_info,PHPCompatibility.Extensions.RemovedExtensions.mysql_DeprecatedRemoved
	$mysql_server_type = mysql_get_server_info( $wpdb->dbh );
}

This can be replaced with:

$mysql_server_type = $wpdb->db_server_info();

The db_server_info() method has the exact same code and is available as of [47451] / #40037.

Attachments (1)

#56484.patch (883 bytes) - added by hilayt24 22 months ago.
Replaced the Fragment

Download all attachments as: .zip

Change History (8)

#1 @SergeyBiryukov
22 months ago

  • Description modified (diff)

#2 @hilayt24
22 months ago

  • Keywords has-patch added; needs-patch removed

Hi @SergeyBiryukov , Thank you for the ticket I replaced the function fragment in WP_Site_Health::prepare_sql_data() .

@hilayt24
22 months ago

Replaced the Fragment

#3 @mukesh27
22 months ago

  • Keywords commit added

Hi there!

Thanks for the patch. #56484.patch LGTM.

Ready for commit.

#4 @SergeyBiryukov
22 months ago

Thanks for the patch! It looks good to me too.

I had a concern about whether this method would be available in custom database drop-ins (wp-content/db.php), but it looks like they are loaded after wpdb, and are supposed to extend the class, rather than completely replace it, though technically the latter is possible too.

@Clorith, do you think this change is safe as is, or should we check if the method exists, just in case, and fall back to the current code if it doesn't? Upon a quick check, popular drop-ins like HyperDB extend the wpdb class, so the patch seems good to go.

Last edited 22 months ago by SergeyBiryukov (previous) (diff)

#5 @hilayt24
22 months ago

  • Keywords good-first-bug removed

#6 @Clorith
22 months ago

I agree that this seems good as is.

I also did some checking, and no plugins I could spot were doing it any other way than by extending, so don't think its a thing we need to be concerned with :)

#7 @SergeyBiryukov
22 months ago

  • Owner set to SergeyBiryukov
  • Resolution set to fixed
  • Status changed from new to closed

In 54065:

Site Health: Use $wpdb->db_server_info() to retrieve database server type.

This updates an older fragment in WP_Site_Health::prepare_sql_data() to use a dedicated $wpdb method introduced later in WordPress 5.5 specifically for retrieving the database server information.

Follow-up to [44986], [47451].

Props hilayt24, mukesh27, Clorith, SergeyBiryukov.
Fixes #56484.

Note: See TracTickets for help on using tickets.