1.20.x database.inc | public DatabaseConnection_mysql::utf8mb4IsSupported() |
Checks whether utf8mb4 support is available on the current database system.
Return value
bool:
Overrides DatabaseConnection::utf8mb4IsSupported
File
- drivers/
database_mysql/ database.inc, line 601 - Database interface code for MySQL database servers.
Class
Code
public function utf8mb4IsSupported() {
// Caching if this method is called multiple times in the same request.
if (isset($this->utf8mb4Supported)) {
return $this->utf8mb4Supported;
}
// Ensure that the MySQL driver supports utf8mb4 encoding.
$version = $this->pdo->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("DROP TABLE IF EXISTS {backdrop_utf8mb4_test}");
$this->query("CREATE TABLE {backdrop_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 IF EXISTS {backdrop_utf8mb4_test}");
return TRUE;
}