function DatabaseConnection_mysql::utf8mb4IsSupported

Checks whether utf8mb4 support is available on the current database system.

Return value

bool

Overrides DatabaseConnection::utf8mb4IsSupported

File

includes/database/mysql/database.inc, line 634

Class

DatabaseConnection_mysql

Code

public function utf8mb4IsSupported() {
  // Ensure that the MySQL driver supports utf8mb4 encoding.
  $version = $this->connection
    ->getAttribute(PDO::ATTR_CLIENT_VERSION);
  if (strpos($version, 'mysqlnd') !== FALSE) {
    // The mysqlnd driver supports utf8mb4 starting at version 5.0.9.
    $version = preg_replace('/^\\D+([\\d.]+).*/', '$1', $version);
    if (version_compare($version, '5.0.9', '<')) {
      return FALSE;
    }
  }
  else {
    // The libmysqlclient driver supports utf8mb4 starting at version 5.5.3.
    if (version_compare($version, '5.5.3', '<')) {
      return FALSE;
    }
  }
  // Ensure that the MySQL server supports large prefixes and utf8mb4.
  try {
    $this->query("CREATE TABLE {drupal_utf8mb4_test} (id VARCHAR(255), PRIMARY KEY(id(255))) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci ROW_FORMAT=DYNAMIC ENGINE=INNODB");
  } catch (Exception $e) {
    return FALSE;
  }
  $this->query("DROP TABLE {drupal_utf8mb4_test}");
  return TRUE;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.