mirror of
https://github.com/Mibew/mibew.git
synced 2025-03-03 18:38:31 +03:00
Use only UTF-8 encoding in database connections
This commit is contained in:
parent
7042f3dd9e
commit
f483c90ee2
@ -63,9 +63,7 @@ if ($act == "silentcreateall") {
|
||||
mysql_query("CREATE DATABASE $mysqldb", $link) or show_install_err(' Query failed: ' . mysql_error($link));
|
||||
} else {
|
||||
mysql_select_db($mysqldb, $link) or show_install_err('Could not select database');
|
||||
if ($force_charset_in_connection) {
|
||||
mysql_query("SET character set utf8", $link);
|
||||
}
|
||||
|
||||
if ($act == "ct") {
|
||||
$curr_tables = get_tables($link);
|
||||
|
@ -198,12 +198,11 @@ function check_connection()
|
||||
|
||||
function check_database($link)
|
||||
{
|
||||
global $mysqldb, $force_charset_in_connection, $page;
|
||||
global $mysqldb, $page;
|
||||
if (mysql_select_db($mysqldb, $link)) {
|
||||
$page['done'][] = getlocal2("install.2.db_exists", array($mysqldb));
|
||||
if ($force_charset_in_connection) {
|
||||
mysql_query("SET character set utf8", $link);
|
||||
}
|
||||
|
||||
return true;
|
||||
} else {
|
||||
$page['nextstep'] = getlocal2("install.2.create", array($mysqldb));
|
||||
|
@ -71,24 +71,6 @@ class Database
|
||||
*/
|
||||
protected $tablesPrefix = '';
|
||||
|
||||
/**
|
||||
* Database connection encoding. Is used only if
|
||||
* Database::$forceCharsetInConnection is set to true.
|
||||
* @var string
|
||||
*
|
||||
* @see Database::$forceCharsetInConnection
|
||||
*/
|
||||
protected $dbEncoding = 'utf8';
|
||||
|
||||
/**
|
||||
* Determine if connection must be forced to charset, specified in
|
||||
* Database::$dbEncoding
|
||||
* @var boolean
|
||||
*
|
||||
* @see Database::$dbEncoding
|
||||
*/
|
||||
protected $forceCharsetInConnection = true;
|
||||
|
||||
/**
|
||||
* Determine if connection to the database must be persistent
|
||||
* @var type
|
||||
@ -156,20 +138,8 @@ class Database
|
||||
* database or not.
|
||||
* @param string $db Database name.
|
||||
* @param string $prefix Database tables prefix
|
||||
* @param boolean $force_charset Control force charset in conection or not.
|
||||
* @param string $encoding Contains connection encoding. Is used only if
|
||||
* $force_charset is equals to TRUE.
|
||||
*/
|
||||
public static function initialize(
|
||||
$host,
|
||||
$user,
|
||||
$pass,
|
||||
$use_pconn,
|
||||
$db,
|
||||
$prefix,
|
||||
$force_charset = false,
|
||||
$encoding = 'utf8'
|
||||
) {
|
||||
public static function initialize($host, $user, $pass, $use_pconn, $db, $prefix) {
|
||||
// Check PDO
|
||||
if (!extension_loaded('PDO')) {
|
||||
throw new \Exception('PDO extension is not loaded');
|
||||
@ -192,9 +162,7 @@ class Database
|
||||
$instance->dbLogin = $user;
|
||||
$instance->dbPass = $pass;
|
||||
$instance->dbName = $db;
|
||||
$instance->dbEncoding = $encoding;
|
||||
$instance->tablesPrefix = preg_replace('/[^A-Za-z0-9_$]/', '', $prefix);
|
||||
$instance->forceCharsetInConnection = $force_charset;
|
||||
$instance->usePersistentConnection = $use_pconn;
|
||||
|
||||
// Create PDO object
|
||||
@ -205,9 +173,8 @@ class Database
|
||||
array(\PDO::ATTR_PERSISTENT => $instance->usePersistentConnection)
|
||||
);
|
||||
|
||||
if ($instance->forceCharsetInConnection) {
|
||||
$instance->dbh->exec("SET NAMES " . $instance->dbh->quote($instance->dbEncoding));
|
||||
}
|
||||
// Force charset in all connections
|
||||
$instance->dbh->exec("SET NAMES utf8");
|
||||
|
||||
// Store instance
|
||||
self::$instance = $instance;
|
||||
|
@ -36,8 +36,6 @@ $mysqllogin = "";
|
||||
$mysqlpass = "";
|
||||
$mysqlprefix = "";
|
||||
|
||||
$force_charset_in_connection = true;
|
||||
|
||||
$use_persistent_connection = false;
|
||||
|
||||
/*
|
||||
|
@ -80,9 +80,7 @@ session_start();
|
||||
$mysqlpass,
|
||||
$use_persistent_connection,
|
||||
$mysqldb,
|
||||
$mysqlprefix,
|
||||
$force_charset_in_connection,
|
||||
'utf8'
|
||||
$mysqlprefix
|
||||
);
|
||||
|
||||
if (function_exists("date_default_timezone_set")) {
|
||||
|
Loading…
Reference in New Issue
Block a user