From ed9d5c383f730f63af0c777b517264fb3569c025 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Thu, 12 Mar 2020 15:53:01 +0000 Subject: [PATCH] Database: Introduce `wpdb::db_server_info()` to retrieve full MySQL server information string as supplied by `mysqli_get_server_info()`. This complements `wpdb::db_version()`, which only returns a numeric version string and strips any additional information, e.g. vendor name. Props clarinetlord, birgire, webaware, pento. Fixes #40037. See #27703. git-svn-id: https://develop.svn.wordpress.org/trunk@47451 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/wp-db.php | 16 ++++++++++++++-- tests/phpunit/tests/db/charset.php | 6 +----- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/wp-includes/wp-db.php b/src/wp-includes/wp-db.php index 7239324547..a87e9621fb 100644 --- a/src/wp-includes/wp-db.php +++ b/src/wp-includes/wp-db.php @@ -3610,14 +3610,26 @@ class wpdb { * * @since 2.7.0 * - * @return null|string Null on failure, version number on success. + * @return string|null Version number on success, null on failure. */ public function db_version() { + return preg_replace( '/[^0-9.].*/', '', $this->db_server_info() ); + } + + /** + * Retrieves full MySQL server information. + * + * @since 5.5.0 + * + * @return string|false Server info on success, false on failure. + */ + public function db_server_info() { if ( $this->use_mysqli ) { $server_info = mysqli_get_server_info( $this->dbh ); } else { $server_info = mysql_get_server_info( $this->dbh ); } - return preg_replace( '/[^0-9.].*/', '', $server_info ); + + return $server_info; } } diff --git a/tests/phpunit/tests/db/charset.php b/tests/phpunit/tests/db/charset.php index ff71fd0b7a..0596c696f3 100644 --- a/tests/phpunit/tests/db/charset.php +++ b/tests/phpunit/tests/db/charset.php @@ -29,11 +29,7 @@ class Tests_DB_Charset extends WP_UnitTestCase { self::$_wpdb = new WpdbExposedMethodsForTesting(); - if ( self::$_wpdb->use_mysqli ) { - self::$server_info = mysqli_get_server_info( self::$_wpdb->dbh ); - } else { - self::$server_info = mysql_get_server_info( self::$_wpdb->dbh ); - } + self::$server_info = self::$_wpdb->db_server_info(); } /**