From 8bd3dca2f7f22a6fe198393b13b7c3496064c52e Mon Sep 17 00:00:00 2001 From: Jakub Vrana Date: Thu, 26 Jun 2014 13:22:35 +0200 Subject: [PATCH] Use utf8mb4 on more places --- adminer/drivers/mysql.inc.php | 4 +--- adminer/dump.inc.php | 2 +- adminer/include/adminer.inc.php | 5 +++-- adminer/include/functions.inc.php | 12 ++++++++++-- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/adminer/drivers/mysql.inc.php b/adminer/drivers/mysql.inc.php index 91cdeb01..021db8a7 100644 --- a/adminer/drivers/mysql.inc.php +++ b/adminer/drivers/mysql.inc.php @@ -292,9 +292,7 @@ if (!defined("DRIVER")) { $connection = new Min_DB; $credentials = $adminer->credentials(); if ($connection->connect($credentials[0], $credentials[1], $credentials[2])) { - $connection->set_charset( // available in MySQLi since PHP 5.0.5 - version_compare($connection->server_info, "5.5.3") > 0 ? "utf8mb4" : "utf8" // SHOW CHARSET would require an extra query - ); + $connection->set_charset(charset($connection)); // available in MySQLi since PHP 5.0.5 $connection->query("SET sql_quote_show_create = 1, autocommit = 1"); return $connection; } diff --git a/adminer/dump.inc.php b/adminer/dump.inc.php index 005ae659..67032522 100644 --- a/adminer/dump.inc.php +++ b/adminer/dump.inc.php @@ -16,7 +16,7 @@ if ($_POST && !$error) { if ($is_sql) { echo "-- Adminer $VERSION " . $drivers[DRIVER] . " dump\n\n"; if ($jush == "sql") { - echo "SET NAMES utf8; + echo "SET NAMES " . charset($connection) . "; SET time_zone = '+00:00'; " . ($_POST["data_style"] ? "SET foreign_key_checks = 0; SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO'; diff --git a/adminer/include/adminer.inc.php b/adminer/include/adminer.inc.php index 2406334e..cc4c40d7 100644 --- a/adminer/include/adminer.inc.php +++ b/adminer/include/adminer.inc.php @@ -412,7 +412,7 @@ username.form['auth[driver]'].onchange(); * @return array expressions to join by AND */ function selectSearchProcess($fields, $indexes) { - global $jush; + global $connection, $jush; $return = array(); foreach ($indexes as $i => $index) { if ($index["type"] == "FULLTEXT" && $_GET["fulltext"][$i] != "") { @@ -443,7 +443,8 @@ username.form['auth[driver]'].onchange(); && (!preg_match("~[\x80-\xFF]~", $val["val"]) || $is_text) ) { $name = idf_escape($name); - $cols[] = ($jush == "sql" && $is_text && !preg_match('~^utf8~', $field["collation"]) ? "CONVERT($name USING utf8)" : $name); + $charset = charset($connection); + $cols[] = ($jush == "sql" && $is_text && !preg_match("~^$charset" . "_~", $field["collation"]) ? "CONVERT($name USING $charset)" : $name); } } $return[] = ($cols ? "(" . implode("$cond OR ", $cols) . "$cond)" : "0"); diff --git a/adminer/include/functions.inc.php b/adminer/include/functions.inc.php index 86246ad8..73a9d772 100644 --- a/adminer/include/functions.inc.php +++ b/adminer/include/functions.inc.php @@ -65,6 +65,14 @@ function bracket_escape($idf, $back = false) { return strtr($idf, ($back ? array_flip($trans) : $trans)); } +/** Get connection charset +* @param Min_DB +* @return string +*/ +function charset($connection) { + return (version_compare($connection->server_info, "5.5.3") > 0 ? "utf8mb4" : "utf8"); // SHOW CHARSET would require an extra query +} + /** Escape for HTML * @param string * @return string @@ -373,7 +381,7 @@ function unique_array($row, $indexes) { * @return string */ function where($where, $fields = array()) { - global $jush; + global $connection, $jush; $return = array(); $function_pattern = '(^[\w\(]+(' . str_replace("_", ".*", preg_quote(idf_escape("_"))) . ')?\)+$)'; //! columns looking like functions foreach ((array) $where["where"] as $key => $val) { @@ -386,7 +394,7 @@ function where($where, $fields = array()) { ) // LIKE because of floats but slow with ints, in MS SQL because of text ; //! enum and set if ($jush == "sql" && preg_match('~char|text~', $fields[$key]["type"]) && preg_match("~[^ -@]~", $val)) { // not just [a-z] to catch non-ASCII characters - $return[] = "$column = " . q($val) . " COLLATE utf8_bin"; + $return[] = "$column = " . q($val) . " COLLATE " . charset($connection) . "_bin"; } } foreach ((array) $where["null"] as $key) {