Skip to content

Commit f6b2f99

Browse files
authored
Correctly identify whether MariaDB supports utf8mb4_520
In older versions of PHP `$db_version` will be `5.5.5` for MariaDB, which prevents the use of the `utf8mb4_unicode_520_ci` collation. See https://core.trac.wordpress.org/changeset/54384
1 parent d8f68ef commit f6b2f99

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

db.php

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1102,22 +1102,33 @@ public function supports_collation( $dbh_or_table = false ) {
11021102
/**
11031103
* Generic function to determine if a database supports a particular feature
11041104
* The additional argument allows the caller to check a specific database.
1105+
*
11051106
* @param string $db_cap the feature
11061107
* @param false|string|resource $dbh_or_table the databaese (the current database, the database housing the specified table, or the database of the mysql resource)
11071108
* @return bool
11081109
*/
11091110
public function has_cap( $db_cap, $dbh_or_table = false ) {
1110-
$version = $this->db_version( $dbh_or_table );
1111+
$db_version = $this->db_version( $dbh_or_table );
1112+
$db_server_info = $this->db_server_info( $dbh_or_table );
1113+
1114+
// Account for MariaDB version being prefixed with '5.5.5-' on older PHP versions.
1115+
if ( '5.5.5' === $db_version && false !== strpos( $db_server_info, 'MariaDB' )
1116+
&& PHP_VERSION_ID < 80016 // PHP 8.0.15 or older.
1117+
) {
1118+
// Strip the '5.5.5-' prefix and set the version to the correct value.
1119+
$db_server_info = preg_replace( '/^5\.5\.5-(.*)/', '$1', $db_server_info );
1120+
$db_version = preg_replace( '/[^0-9.].*/', '', $db_server_info );
1121+
}
11111122

11121123
switch ( strtolower( $db_cap ) ) :
11131124
case 'collation':
11141125
case 'group_concat':
11151126
case 'subqueries':
1116-
return version_compare( $version, '4.1', '>=' );
1127+
return version_compare( $db_version, '4.1', '>=' );
11171128
case 'set_charset':
1118-
return version_compare( $version, '5.0.7', '>=' );
1129+
return version_compare( $db_version, '5.0.7', '>=' );
11191130
case 'utf8mb4': // @since WP 4.1.0
1120-
if ( version_compare( $version, '5.5.3', '<' ) ) {
1131+
if ( version_compare( $db_version, '5.5.3', '<' ) ) {
11211132
return false;
11221133
}
11231134
if ( $this->use_mysqli ) {
@@ -1137,7 +1148,7 @@ public function has_cap( $db_cap, $dbh_or_table = false ) {
11371148
return version_compare( $client_version, '5.5.3', '>=' );
11381149
}
11391150
case 'utf8mb4_520': // since WP 4.6
1140-
return $this->has_cap( 'utf8mb4', $dbh_or_table ) && version_compare( $version, '5.6', '>=' );
1151+
return $this->has_cap( 'utf8mb4', $dbh_or_table ) && version_compare( $db_version, '5.6', '>=' );
11411152
endswitch;
11421153

11431154
return false;

0 commit comments

Comments
 (0)