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
This commit is contained in:
Sergey Biryukov 2020-03-12 15:53:01 +00:00
parent 60edf36394
commit ed9d5c383f
2 changed files with 15 additions and 7 deletions

View File

@ -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;
}
}

View File

@ -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();
}
/**