Centralize setting MySQL charset
This commit is contained in:
parent
9b34f7906f
commit
1127082dd2
2 changed files with 17 additions and 14 deletions
|
@ -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;
|
||||
}
|
||||
|
|
2
externals/jush
vendored
2
externals/jush
vendored
|
@ -1 +1 @@
|
|||
Subproject commit f1aba878f01e76bdd759372d6b8ab5ad6f330a29
|
||||
Subproject commit 4702f10b84ee2be95d16204bb3cded96e74e8cc6
|
Loading…
Add table
Reference in a new issue