code { background-color: #EEE; padding: 2px 6px; font-weight: bold; color: #00C; }
li { line-height: 125%; }
.error { color: #C00; }
.success { color: #090; }
Test MySQL support for 'utf8mb4' charset
This script will test if your hosting provider supports the utf8mb4
character set.
This is the modern recommended character set that is needed to support non-english languages, emojis, etc.
It's enabled by default in MySQL 5.5 which was released over 7 years ago (link).
If your host doesn't support utfmb4 please ask them to upgrade.
__HTML__;
//
print "";
// connect to server
print "- Current PHP version:
v" .phpversion(). "
\n";
print "- MySQL Client library:
" .mysqli_get_client_info(). "
\n";
print "- Attempting to connect to database server on host
$mysqlHost
as user $mysqlUser
\n";
$mysqli = @new mysqli($mysqlHost, $mysqlUser, $mysqlPass);
if ($mysqli->connect_errno) {
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error. "
\n";
exit;
}
else {
print "- Success!";
$result = $mysqli->query("SHOW VARIABLES LIKE 'version_comment'") or die("MySQL Error: " .$mysqli->error. "\n");
$databaseServer = $result->fetch_row()[1];
$databaseVersion = $mysqli->server_info;
print " Database server:
$databaseServer v$databaseVersion
\n";
}
print "
";
// list character sets
print "- List supported charsets,
SHOW CHARACTER SET
output:";
print "- ";
$charsets = [];
$result = $mysqli->query("SHOW CHARACTER SET") or die("MySQL Error: " .$mysqli->error. "\n");
while ($row = $result->fetch_row()) { $charsets[] = $row[0]; }
sort($charsets);
$charsetsCSV = implode(", ", $charsets);
$charsetsCSV = preg_replace("/(utf8mb4)/", "
$1
", $charsetsCSV);
echo $charsetsCSV;
print "
\n";
// switch character set
print "- Try setting charset to
utf8mb4
- ";
$success = $mysqli->set_charset("utf8mb4");
if (!$success) {
echo "
Failed to set charset: " .$mysqli->error. "
\n";
}
else {
print "Success! Character set set to: " .$mysqli->character_set_name(). "
";
}
print "
\n";
// show status
if ($success) { print "Success, everything is working!
"; }
else { print "Failure, couldn't set charset. Contact your host for support!
"; }
//
print "
\n";
exit;