Skip to content

Correctly identify whether the server supports utf8mb4_520 #143

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

Open
wants to merge 2 commits into
base: trunk
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
21 changes: 16 additions & 5 deletions db.php
Original file line number Diff line number Diff line change
Expand Up @@ -1102,22 +1102,33 @@ public function supports_collation( $dbh_or_table = false ) {
/**
* Generic function to determine if a database supports a particular feature
* The additional argument allows the caller to check a specific database.
*
* @param string $db_cap the feature
* @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)
* @return bool
*/
public function has_cap( $db_cap, $dbh_or_table = false ) {
$version = $this->db_version( $dbh_or_table );
$db_version = $this->db_version( $dbh_or_table );
$db_server_info = $this->db_server_info( $dbh_or_table );

// Account for MariaDB version being prefixed with '5.5.5-' on older PHP versions.
if ( '5.5.5' === $db_version && false !== strpos( $db_server_info, 'MariaDB' )
&& PHP_VERSION_ID < 80016 // PHP 8.0.15 or older.
) {
// Strip the '5.5.5-' prefix and set the version to the correct value.
$db_server_info = preg_replace( '/^5\.5\.5-(.*)/', '$1', $db_server_info );
$db_version = preg_replace( '/[^0-9.].*/', '', $db_server_info );
}

switch ( strtolower( $db_cap ) ) :
case 'collation':
case 'group_concat':
case 'subqueries':
return version_compare( $version, '4.1', '>=' );
return version_compare( $db_version, '4.1', '>=' );
case 'set_charset':
return version_compare( $version, '5.0.7', '>=' );
return version_compare( $db_version, '5.0.7', '>=' );
case 'utf8mb4': // @since WP 4.1.0
if ( version_compare( $version, '5.5.3', '<' ) ) {
if ( version_compare( $db_version, '5.5.3', '<' ) ) {
return false;
}
if ( $this->use_mysqli ) {
Expand All @@ -1137,7 +1148,7 @@ public function has_cap( $db_cap, $dbh_or_table = false ) {
return version_compare( $client_version, '5.5.3', '>=' );
}
case 'utf8mb4_520': // since WP 4.6
return $this->has_cap( 'utf8mb4', $dbh_or_table ) && version_compare( $version, '5.6', '>=' );
return $this->has_cap( 'utf8mb4', $dbh_or_table ) && version_compare( $db_version, '5.6', '>=' );
endswitch;

return false;
Expand Down
Loading