public function DatabaseConnection_mysql::utf8mb4IsSupported

public 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 224
Database interface code for MySQL database servers.

Class

DatabaseConnection_mysql

Code

public function utf8mb4IsSupported() {
  // Ensure that the MySQL driver supports utf8mb4 encoding.
  $version = $this->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");
  }
  catch (Exception $e) {
    return FALSE;
  }
  $this->query("DROP TABLE {drupal_utf8mb4_test}");
  return TRUE;
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/includes!database!mysql!database.inc/function/DatabaseConnection_mysql::utf8mb4IsSupported/7.x