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));
|
mysql_query("CREATE DATABASE $mysqldb", $link) or show_install_err(' Query failed: ' . mysql_error($link));
|
||||||
} else {
|
} else {
|
||||||
mysql_select_db($mysqldb, $link) or show_install_err('Could not select database');
|
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);
|
||||||
mysql_query("SET character set utf8", $link);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($act == "ct") {
|
if ($act == "ct") {
|
||||||
$curr_tables = get_tables($link);
|
$curr_tables = get_tables($link);
|
||||||
|
@ -198,12 +198,11 @@ function check_connection()
|
|||||||
|
|
||||||
function check_database($link)
|
function check_database($link)
|
||||||
{
|
{
|
||||||
global $mysqldb, $force_charset_in_connection, $page;
|
global $mysqldb, $page;
|
||||||
if (mysql_select_db($mysqldb, $link)) {
|
if (mysql_select_db($mysqldb, $link)) {
|
||||||
$page['done'][] = getlocal2("install.2.db_exists", array($mysqldb));
|
$page['done'][] = getlocal2("install.2.db_exists", array($mysqldb));
|
||||||
if ($force_charset_in_connection) {
|
mysql_query("SET character set utf8", $link);
|
||||||
mysql_query("SET character set utf8", $link);
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
$page['nextstep'] = getlocal2("install.2.create", array($mysqldb));
|
$page['nextstep'] = getlocal2("install.2.create", array($mysqldb));
|
||||||
|
@ -71,24 +71,6 @@ class Database
|
|||||||
*/
|
*/
|
||||||
protected $tablesPrefix = '';
|
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
|
* Determine if connection to the database must be persistent
|
||||||
* @var type
|
* @var type
|
||||||
@ -156,20 +138,8 @@ class Database
|
|||||||
* database or not.
|
* database or not.
|
||||||
* @param string $db Database name.
|
* @param string $db Database name.
|
||||||
* @param string $prefix Database tables prefix
|
* @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(
|
public static function initialize($host, $user, $pass, $use_pconn, $db, $prefix) {
|
||||||
$host,
|
|
||||||
$user,
|
|
||||||
$pass,
|
|
||||||
$use_pconn,
|
|
||||||
$db,
|
|
||||||
$prefix,
|
|
||||||
$force_charset = false,
|
|
||||||
$encoding = 'utf8'
|
|
||||||
) {
|
|
||||||
// Check PDO
|
// Check PDO
|
||||||
if (!extension_loaded('PDO')) {
|
if (!extension_loaded('PDO')) {
|
||||||
throw new \Exception('PDO extension is not loaded');
|
throw new \Exception('PDO extension is not loaded');
|
||||||
@ -192,9 +162,7 @@ class Database
|
|||||||
$instance->dbLogin = $user;
|
$instance->dbLogin = $user;
|
||||||
$instance->dbPass = $pass;
|
$instance->dbPass = $pass;
|
||||||
$instance->dbName = $db;
|
$instance->dbName = $db;
|
||||||
$instance->dbEncoding = $encoding;
|
|
||||||
$instance->tablesPrefix = preg_replace('/[^A-Za-z0-9_$]/', '', $prefix);
|
$instance->tablesPrefix = preg_replace('/[^A-Za-z0-9_$]/', '', $prefix);
|
||||||
$instance->forceCharsetInConnection = $force_charset;
|
|
||||||
$instance->usePersistentConnection = $use_pconn;
|
$instance->usePersistentConnection = $use_pconn;
|
||||||
|
|
||||||
// Create PDO object
|
// Create PDO object
|
||||||
@ -205,9 +173,8 @@ class Database
|
|||||||
array(\PDO::ATTR_PERSISTENT => $instance->usePersistentConnection)
|
array(\PDO::ATTR_PERSISTENT => $instance->usePersistentConnection)
|
||||||
);
|
);
|
||||||
|
|
||||||
if ($instance->forceCharsetInConnection) {
|
// Force charset in all connections
|
||||||
$instance->dbh->exec("SET NAMES " . $instance->dbh->quote($instance->dbEncoding));
|
$instance->dbh->exec("SET NAMES utf8");
|
||||||
}
|
|
||||||
|
|
||||||
// Store instance
|
// Store instance
|
||||||
self::$instance = $instance;
|
self::$instance = $instance;
|
||||||
|
@ -36,8 +36,6 @@ $mysqllogin = "";
|
|||||||
$mysqlpass = "";
|
$mysqlpass = "";
|
||||||
$mysqlprefix = "";
|
$mysqlprefix = "";
|
||||||
|
|
||||||
$force_charset_in_connection = true;
|
|
||||||
|
|
||||||
$use_persistent_connection = false;
|
$use_persistent_connection = false;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -80,9 +80,7 @@ session_start();
|
|||||||
$mysqlpass,
|
$mysqlpass,
|
||||||
$use_persistent_connection,
|
$use_persistent_connection,
|
||||||
$mysqldb,
|
$mysqldb,
|
||||||
$mysqlprefix,
|
$mysqlprefix
|
||||||
$force_charset_in_connection,
|
|
||||||
'utf8'
|
|
||||||
);
|
);
|
||||||
|
|
||||||
if (function_exists("date_default_timezone_set")) {
|
if (function_exists("date_default_timezone_set")) {
|
||||||
|
Loading…
Reference in New Issue
Block a user