From 365003d0d8f6bf05852ddbd9a1f2ffd992ac3d71 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Mon, 6 Oct 2014 19:26:37 +0200 Subject: Implement force utf8 option for mysql db --- config.php.example | 2 +- inc/database.inc.php | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/config.php.example b/config.php.example index 2e0ec117..1fded4da 100644 --- a/config.php.example +++ b/config.php.example @@ -11,7 +11,7 @@ define('CONFIG_SQL_DSN', 'mysql:dbname=openslx;host=localhost'); define('CONFIG_SQL_USER', 'openslx'); define('CONFIG_SQL_PASS', '%MYSQL_OPENSLX_PASS%'); // Set this to true if you mysql server doesn't default to UTF-8 on new connections -define('CONFIG_SQL_FORCE_UTF8', false); +define('CONFIG_SQL_FORCE_UTF8', true); define('CONFIG_TGZ_LIST_DIR', '/opt/openslx/configs'); diff --git a/inc/database.inc.php b/inc/database.inc.php index a729b7fc..0d48c23c 100644 --- a/inc/database.inc.php +++ b/inc/database.inc.php @@ -32,7 +32,10 @@ class Database if (self::$dbh !== false) return; try { - self::$dbh = new PDO(CONFIG_SQL_DSN, CONFIG_SQL_USER, CONFIG_SQL_PASS, array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8")); + if (CONFIG_SQL_FORCE_UTF8) + self::$dbh = new PDO(CONFIG_SQL_DSN, CONFIG_SQL_USER, CONFIG_SQL_PASS, array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8")); + else + self::$dbh = new PDO(CONFIG_SQL_DSN, CONFIG_SQL_USER, CONFIG_SQL_PASS); } catch (PDOException $e) { Util::traceError('Connecting to the local database failed: ' . $e->getMessage()); } -- cgit v1.2.3-55-g7522