From 305dda7079bbf0bc2904ea526aeea22328146423 Mon Sep 17 00:00:00 2001
From: Marius Cramer <m.cramer@pixcept.de>
Date: Thu, 16 Apr 2015 10:52:58 +0200
Subject: [PATCH] - changed some things in mysql lib for installer

---
 install/install.php                |  6 ++----
 install/lib/installer_base.lib.php |  4 ++--
 install/lib/mysql.lib.php          | 18 +++++++++++++++---
 install/update.php                 |  6 ++----
 4 files changed, 21 insertions(+), 13 deletions(-)

diff --git a/install/install.php b/install/install.php
index 9f7cca5b5b..e5f0abea77 100644
--- a/install/install.php
+++ b/install/install.php
@@ -449,10 +449,8 @@ if($install_mode == 'standard') {
 		// initialize the connection to the master database
 		$inst->dbmaster = new db();
 		if($inst->dbmaster->linkId) $inst->dbmaster->closeConn();
-		$inst->dbmaster->dbHost = $conf['mysql']["master_host"];
-		$inst->dbmaster->dbName = $conf['mysql']["master_database"];
-		$inst->dbmaster->dbUser = $conf['mysql']["master_admin_user"];
-		$inst->dbmaster->dbPass = $conf['mysql']["master_admin_password"];
+		$inst->dbmaster->setDBData($conf['mysql']["master_host"], $conf['mysql']["master_admin_user"], $conf['mysql']["master_admin_password"]);
+		$inst->dbmaster->setDBName($conf['mysql']["master_database"]);
 
 	} else {
 		// the master DB is the same then the slave DB
diff --git a/install/lib/installer_base.lib.php b/install/lib/installer_base.lib.php
index cba3056512..2d14c83695 100644
--- a/install/lib/installer_base.lib.php
+++ b/install/lib/installer_base.lib.php
@@ -172,7 +172,7 @@ class installer_base {
 		}
 
 		//* Set the database name in the DB library
-		$this->db->dbName = $conf['mysql']['database'];
+		$this->db->setDBName($conf['mysql']['database']);
 
 		//* Load the database dump into the database, if database contains no tables
 		$db_tables = $this->db->getTables();
@@ -224,7 +224,7 @@ class installer_base {
 		$this->db->query('FLUSH PRIVILEGES;');
 
 		//* Set the database name in the DB library
-		$this->db->dbName = $conf['mysql']['database'];
+		$this->db->setDBName($conf['mysql']['database']);
 
 		$tpl_ini_array = ini_to_array(rf('tpl/server.ini.master'));
 
diff --git a/install/lib/mysql.lib.php b/install/lib/mysql.lib.php
index d99793bf2c..3a6d483ab3 100644
--- a/install/lib/mysql.lib.php
+++ b/install/lib/mysql.lib.php
@@ -69,7 +69,7 @@ class db extends mysqli
 		
 		if($this->_iConnId) return true;
 		$this->dbHost = $conf["mysql"]["host"];
-		$this->dbName = $conf["mysql"]["database"];
+		$this->dbName = false;//$conf["mysql"]["database"];
 		$this->dbUser = $conf["mysql"]["admin_user"];
 		$this->dbPass = $conf["mysql"]["admin_password"];
 		$this->dbCharset = $conf["mysql"]["charset"];
@@ -90,13 +90,25 @@ class db extends mysqli
 			$this->_sqlerror('Zugriff auf Datenbankserver fehlgeschlagen! / Database server not accessible!');
 			return false;
 		}
+		
+		if($this->dbName) $this->setDBName($this->dbName);
+
+		$this->_setCharset();
+	}
+	
+	public function setDBData($host, $user, $password) {
+		$this->dbHost = $host;
+		$this->dbUser = $user;
+		$this->dbPass = $password;
+	}
+	
+	public function setDBName($name) {
+		$this->dbName = $name;
 		if(!((bool)mysqli_query( $this->_iConnId, 'USE `' . $this->dbName . '`'))) {
 			$this->close();
 			$this->_sqlerror('Datenbank nicht gefunden / Database not found');
 			return false;
 		}
-
-		$this->_setCharset();
 	}
 	
 	public function close() {
diff --git a/install/update.php b/install/update.php
index e0a6bd2287..43942943f1 100644
--- a/install/update.php
+++ b/install/update.php
@@ -267,10 +267,8 @@ if($conf['mysql']['master_slave_setup'] == 'y') {
 	// initialize the connection to the master database
 	$inst->dbmaster = new db();
 	if($inst->dbmaster->linkId) $inst->dbmaster->closeConn();
-	$inst->dbmaster->dbHost = $conf['mysql']["master_host"];
-	$inst->dbmaster->dbName = $conf['mysql']["master_database"];
-	$inst->dbmaster->dbUser = $conf['mysql']["master_admin_user"];
-	$inst->dbmaster->dbPass = $conf['mysql']["master_admin_password"];
+	$inst->dbmaster->setDBData($conf['mysql']["master_host"], $conf['mysql']["master_admin_user"], $conf['mysql']["master_admin_password"]);
+	$inst->dbmaster->setDBName($conf['mysql']["master_database"]);
 } else {
 	$inst->dbmaster = $inst->db;
 }
-- 
GitLab