From 1127082dd2f7b27af70933d248adda91eb3c5eb4 Mon Sep 17 00:00:00 2001 From: Jakub Vrana Date: Tue, 24 Jun 2014 14:53:04 +0200 Subject: [PATCH] Centralize setting MySQL charset --- adminer/drivers/mysql.inc.php | 29 ++++++++++++++++------------- externals/jush | 2 +- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/adminer/drivers/mysql.inc.php b/adminer/drivers/mysql.inc.php index a4e192e3..8778bde7 100644 --- a/adminer/drivers/mysql.inc.php +++ b/adminer/drivers/mysql.inc.php @@ -24,13 +24,6 @@ if (!defined("DRIVER")) { (is_numeric($port) ? $port : ini_get("mysqli.default_port")), (!is_numeric($port) ? $port : null) ); - if ($return) { - if (method_exists($this, 'set_charset')) { - $this->set_charset("utf8"); - } else { - $this->query("SET NAMES utf8"); - } - } return $return; } @@ -75,17 +68,23 @@ if (!defined("DRIVER")) { ); if ($this->_link) { $this->server_info = mysql_get_server_info($this->_link); - if (function_exists('mysql_set_charset')) { - mysql_set_charset("utf8", $this->_link); - } else { - $this->query("SET NAMES utf8"); - } } else { $this->error = mysql_error(); } return (bool) $this->_link; } + /** Sets the client character set + * @param string + * @return bool + */ + function set_charset($charset) { + if (function_exists('mysql_set_charset')) { + return mysql_set_charset($charset, $this->_link); + } + return $this->query("SET NAMES $charset"); + } + /** Quote string to use in SQL * @param string * @return string escaped string enclosed in ' @@ -212,10 +211,13 @@ if (!defined("DRIVER")) { function connect($server, $username, $password) { $this->dsn("mysql:charset=utf8;host=" . str_replace(":", ";unix_socket=", preg_replace('~:(\\d)~', ';port=\\1', $server)), $username, $password); - $this->query("SET NAMES utf8"); // charset in DSN is ignored before PHP 5.3.6 return true; } + function set_charset($charset) { + $this->query("SET NAMES $charset"); // charset in DSN is ignored before PHP 5.3.6 + } + function select_db($database) { // database selection is separated from the connection so dbname in DSN can't be used return $this->query("USE " . idf_escape($database)); @@ -290,6 +292,7 @@ if (!defined("DRIVER")) { $connection = new Min_DB; $credentials = $adminer->credentials(); if ($connection->connect($credentials[0], $credentials[1], $credentials[2])) { + $connection->set_charset("utf8"); // available in MySQLi since PHP 5.0.5 $connection->query("SET sql_quote_show_create = 1, autocommit = 1"); return $connection; } diff --git a/externals/jush b/externals/jush index f1aba878..4702f10b 160000 --- a/externals/jush +++ b/externals/jush @@ -1 +1 @@ -Subproject commit f1aba878f01e76bdd759372d6b8ab5ad6f330a29 +Subproject commit 4702f10b84ee2be95d16204bb3cded96e74e8cc6