From f1926a01df8871cdacb29c97ffbfd7ff18d1610a Mon Sep 17 00:00:00 2001
From: Till Brehm <tbrehm@ispconfig.org>
Date: Tue, 9 Feb 2016 17:56:40 +0100
Subject: [PATCH] Fixed problems that prevented ISPConfig to run on PHP 7,
 Issue #3716

---
 install/install.php                              | 10 +++++-----
 install/lib/mysql.lib.php                        |  4 ++--
 install/uninstall-fedora.php                     | 12 ++++++------
 install/uninstall.php                            | 12 ++++++------
 install/update.php                               |  8 ++++----
 server/lib/classes/db_mysql.inc.php              | 10 +++++-----
 server/lib/classes/system.inc.php                |  2 +-
 .../software_update_plugin.inc.php               | 16 ++++++++--------
 8 files changed, 37 insertions(+), 37 deletions(-)

diff --git a/install/install.php b/install/install.php
index cab7069d39..c023e8fe7c 100644
--- a/install/install.php
+++ b/install/install.php
@@ -188,7 +188,7 @@ do {
 } while (!$check);
 
 // Check if the mysql functions are loaded in PHP
-if(!function_exists('mysql_connect')) die('No PHP MySQL functions available. Please ensure that the PHP MySQL module is loaded.');
+if(!function_exists('mysqli_connect')) die('No PHP MySQLi functions available. Please ensure that the PHP MySQL module is loaded.');
 
 //** Get MySQL root credentials
 $finished = false;
@@ -208,7 +208,7 @@ do {
 	}
 
 	//* Initialize the MySQL server connection
-	if(@mysql_connect($tmp_mysql_server_host . ':' . (int)$tmp_mysql_server_port, $tmp_mysql_server_admin_user, $tmp_mysql_server_admin_password)) {
+	if(@mysqli_connect($tmp_mysql_server_host . ':' . (int)$tmp_mysql_server_port, $tmp_mysql_server_admin_user, $tmp_mysql_server_admin_password)) {
 		$conf['mysql']['host'] = $tmp_mysql_server_host;
 		$conf['mysql']['port'] = $tmp_mysql_server_port;
 		$conf['mysql']['admin_user'] = $tmp_mysql_server_admin_user;
@@ -217,7 +217,7 @@ do {
 		$conf['mysql']['charset'] = $tmp_mysql_server_charset;
 		$finished = true;
 	} else {
-		swriteln($inst->lng('Unable to connect to the specified MySQL server').' '.mysql_error());
+		swriteln($inst->lng('Unable to connect to the specified MySQL server').' '.mysqli_error());
 	}
 } while ($finished == false);
 unset($finished);
@@ -553,7 +553,7 @@ if($install_mode == 'standard') {
 			$tmp_mysql_server_database = $inst->free_query('MySQL master server database name', $conf['mysql']['master_database'],'mysql_master_database');
 
 			//* Initialize the MySQL server connection
-			if(@mysql_connect($tmp_mysql_server_host . ':' . (int)$tmp_mysql_server_port, $tmp_mysql_server_admin_user, $tmp_mysql_server_admin_password)) {
+			if(@mysqli_connect($tmp_mysql_server_host . ':' . (int)$tmp_mysql_server_port, $tmp_mysql_server_admin_user, $tmp_mysql_server_admin_password)) {
 				$conf['mysql']['master_host'] = $tmp_mysql_server_host;
 				$conf['mysql']['master_port'] = $tmp_mysql_server_port;
 				$conf['mysql']['master_admin_user'] = $tmp_mysql_server_admin_user;
@@ -561,7 +561,7 @@ if($install_mode == 'standard') {
 				$conf['mysql']['master_database'] = $tmp_mysql_server_database;
 				$finished = true;
 			} else {
-				swriteln($inst->lng('Unable to connect to mysql server').' '.mysql_error());
+				swriteln($inst->lng('Unable to connect to mysql server').' '.mysqli_error());
 			}
 		} while ($finished == false);
 		unset($finished);
diff --git a/install/lib/mysql.lib.php b/install/lib/mysql.lib.php
index 11fd2ec37d..7cf06ee044 100644
--- a/install/lib/mysql.lib.php
+++ b/install/lib/mysql.lib.php
@@ -776,7 +776,7 @@ class db_result {
 	 *
 	 * @access private
 	 */
-	public function db_result($iResId, $iConnection) {
+	public function __construct($iResId, $iConnection) {
 		$this->_iResId = $iResId;
 		$this->_iConnection = $iConnection;
 	}
@@ -902,7 +902,7 @@ class fakedb_result {
 	 *
 	 * @access private
 	 */
-	public function fakedb_result($aData) {
+	public function __construct($aData) {
 		$this->aResultData = $aData;
 		$this->aLimitedData = $aData;
 		reset($this->aLimitedData);
diff --git a/install/uninstall-fedora.php b/install/uninstall-fedora.php
index b1d7e47752..8aa5fcf68e 100644
--- a/install/uninstall-fedora.php
+++ b/install/uninstall-fedora.php
@@ -65,16 +65,16 @@ if($do_uninstall == 'yes') {
 	//exec("/etc/init.d/mysqld stop");
 	//exec("rm -rf /var/lib/mysql/".$conf["db_database"]);
 	//exec("/etc/init.d/mysqld start");
-	$link = mysql_connect($clientdb_host, $clientdb_user, $clientdb_password);
+	$link = mysqli_connect($clientdb_host, $clientdb_user, $clientdb_password);
 	if (!$link) {
 		echo "Unable to connect to the database'.mysql_error($link)";
 	} else {
-		$result=mysql_query("DROP DATABASE ".$conf['db_database']."';", $link);
-		if (!$result) echo "Unable to remove the ispconfig-database ".$conf['db_database']." ".mysql_error($link)."\n";
-		$result=mysql_query("DROP USER '".$conf['db_user'] ."';");
-		if (!$result) echo "Unable to remove the ispconfig-database-user ".$conf['db_user']." ".mysql_error($link)."\n";
+		$result=mysqli_query($link,"DROP DATABASE ".$conf['db_database']."';");
+		if (!$result) echo "Unable to remove the ispconfig-database ".$conf['db_database']." ".mysqli_error($link)."\n";
+		$result=mysqli_query($link, "DROP USER '".$conf['db_user'] ."';");
+		if (!$result) echo "Unable to remove the ispconfig-database-user ".$conf['db_user']." ".mysqli_error($link)."\n";
 	}
-	mysql_close($link);
+	mysqli_close($link);
 
 	// Deleting the symlink in /var/www
 	// Apache
diff --git a/install/uninstall.php b/install/uninstall.php
index 111f574663..198a145a5a 100644
--- a/install/uninstall.php
+++ b/install/uninstall.php
@@ -60,16 +60,16 @@ if($do_uninstall == 'yes') {
 
 	echo "\n\n>> Uninstalling ISPConfig 3... \n\n";
 
-	$link = mysql_connect($clientdb_host, $clientdb_user, $clientdb_password);
+	$link = mysqli_connect($clientdb_host, $clientdb_user, $clientdb_password);
 	if (!$link) {
 		echo "Unable to connect to the database'.mysql_error($link)";
 	} else {
-		$result=mysql_query("DROP DATABASE ".$conf['db_database']."';", $link);
-		if (!$result) echo "Unable to remove the ispconfig-database ".$conf['db_database']." ".mysql_error($link)."\n";
-		$result=mysql_query("DROP USER '".$conf['db_user'] ."';");
-	        if (!$result) echo "Unable to remove the ispconfig-database-user ".$conf['db_user']." ".mysql_error($link)."\n";
+		$result=mysqli_query($link,"DROP DATABASE ".$conf['db_database']."';");
+		if (!$result) echo "Unable to remove the ispconfig-database ".$conf['db_database']." ".mysqli_error($link)."\n";
+		$result=mysqli_query($link,"DROP USER '".$conf['db_user'] ."';");
+	        if (!$result) echo "Unable to remove the ispconfig-database-user ".$conf['db_user']." ".mysqli_error($link)."\n";
 	}
-	mysql_close($link);
+	mysqli_close($link);
 	
 	// Deleting the symlink in /var/www
 	// Apache
diff --git a/install/update.php b/install/update.php
index 504a63713e..6422e54fef 100644
--- a/install/update.php
+++ b/install/update.php
@@ -226,10 +226,10 @@ $clientdb_password  = '';
 //** Test mysql root connection
 $finished = false;
 do {
-	if(@mysql_connect($conf["mysql"]["host"], $conf["mysql"]["admin_user"], $conf["mysql"]["admin_password"])) {
+	if(@mysqli_connect($conf["mysql"]["host"], $conf["mysql"]["admin_user"], $conf["mysql"]["admin_password"])) {
 		$finished = true;
 	} else {
-		swriteln($inst->lng('Unable to connect to mysql server').' '.mysql_error());
+		swriteln($inst->lng('Unable to connect to mysql server').' '.mysqli_error());
 		$conf["mysql"]["admin_password"] = $inst->free_query('MySQL root password', $conf['mysql']['admin_password'],'mysql_root_password');
 	}
 } while ($finished == false);
@@ -255,7 +255,7 @@ if($conf['mysql']['master_slave_setup'] == 'y') {
 		$tmp_mysql_server_database = $inst->free_query('MySQL master server database name', $conf['mysql']['master_database'],'mysql_master_database');
 
 		//* Initialize the MySQL server connection
-		if(@mysql_connect($tmp_mysql_server_host . ':' . (int)$tmp_mysql_server_port, $tmp_mysql_server_admin_user, $tmp_mysql_server_admin_password)) {
+		if(@mysqli_connect($tmp_mysql_server_host . ':' . (int)$tmp_mysql_server_port, $tmp_mysql_server_admin_user, $tmp_mysql_server_admin_password)) {
 			$conf['mysql']['master_host'] = $tmp_mysql_server_host;
 			$conf['mysql']['master_port'] = $tmp_mysql_server_port;
 			$conf['mysql']['master_admin_user'] = $tmp_mysql_server_admin_user;
@@ -263,7 +263,7 @@ if($conf['mysql']['master_slave_setup'] == 'y') {
 			$conf['mysql']['master_database'] = $tmp_mysql_server_database;
 			$finished = true;
 		} else {
-			swriteln($inst->lng('Unable to connect to mysql server').' '.mysql_error());
+			swriteln($inst->lng('Unable to connect to mysql server').' '.mysqli_error());
 		}
 	} while ($finished == false);
 	unset($finished);
diff --git a/server/lib/classes/db_mysql.inc.php b/server/lib/classes/db_mysql.inc.php
index 52a5e50aa0..e3d0c69721 100644
--- a/server/lib/classes/db_mysql.inc.php
+++ b/server/lib/classes/db_mysql.inc.php
@@ -556,19 +556,19 @@ class db extends mysqli
 		global $app;
 		include 'lib/mysql_clientdb.conf';
 		/* Connect to the database */
-		$link = mysql_connect($clientdb_host, $clientdb_user, $clientdb_password);
+		$link = mysqli_connect($clientdb_host, $clientdb_user, $clientdb_password);
 		if (!$link) {
-			$app->log('Unable to connect to the database'.mysql_error($link), LOGLEVEL_DEBUG);
+			$app->log('Unable to connect to the database'.mysqli_error($link), LOGLEVEL_DEBUG);
 			return;
 		}
 		/* Get database-size from information_schema */
-		$result=mysql_query("SELECT SUM(data_length+index_length) FROM information_schema.TABLES WHERE table_schema='".mysql_real_escape_string($database_name)."';", $link);
+		$result=mysqli_query("SELECT SUM(data_length+index_length) FROM information_schema.TABLES WHERE table_schema='".mysqli_real_escape_string($database_name)."';", $link);
 		$this->close;
 		if (!$result) {
-			$app->log('Unable to get the database-size'.mysql_error($link), LOGLEVEL_DEBUG);
+			$app->log('Unable to get the database-size'.mysqli_error($link), LOGLEVEL_DEBUG);
 			return;
 		}
-		$database_size = mysql_fetch_row($result);
+		$database_size = mysqli_fetch_row($result);
 		return $database_size[0];
 	}
 
diff --git a/server/lib/classes/system.inc.php b/server/lib/classes/system.inc.php
index 739e8220e1..2c36c38442 100644
--- a/server/lib/classes/system.inc.php
+++ b/server/lib/classes/system.inc.php
@@ -44,7 +44,7 @@ class system{
 	 */
 
 
-	public function system(){
+	public function __construct(){
 		//global $go_info;
 		//$this->server_id = $go_info['isp']['server_id'];
 		//$this->server_conf = $go_info['isp']['server_conf'];
diff --git a/server/plugins-available/software_update_plugin.inc.php b/server/plugins-available/software_update_plugin.inc.php
index ae6b79cfc4..bd8159e1ab 100644
--- a/server/plugins-available/software_update_plugin.inc.php
+++ b/server/plugins-available/software_update_plugin.inc.php
@@ -246,29 +246,29 @@ class software_update_plugin {
 			}
 
 			//* Connect to the database
-			$link = mysql_connect($clientdb_host, $clientdb_user, $clientdb_password);
+			$link = mysqli_connect($clientdb_host, $clientdb_user, $clientdb_password);
 			if (!$link) {
-				$app->log('Unable to connect to the database'.mysql_error($link), LOGLEVEL_ERROR);
+				$app->log('Unable to connect to the database'.mysqli_error($link), LOGLEVEL_ERROR);
 				return;
 			}
 
 			$query_charset_table = '';
 
 			//* Create the new database
-			if (mysql_query('CREATE DATABASE '.mysql_real_escape_string($db_config['database_name']).$query_charset_table, $link)) {
+			if (mysqli_query($link,'CREATE DATABASE '.mysqli_real_escape_string($link, $db_config['database_name']).$query_charset_table, $link)) {
 				$app->log('Created MySQL database: '.$db_config['database_name'], LOGLEVEL_DEBUG);
 			} else {
-				$app->log('Unable to connect to the database'.mysql_error($link), LOGLEVEL_ERROR);
+				$app->log('Unable to connect to the database'.mysqli_error($link), LOGLEVEL_ERROR);
 			}
 
-			if(mysql_query("GRANT ALL ON ".mysql_real_escape_string($db_config['database_name'], $link).".* TO '".mysql_real_escape_string($db_config['database_user'], $link)."'@'".$db_config['database_host']."' IDENTIFIED BY '".mysql_real_escape_string($db_config['database_password'], $link)."';", $link)) {
+			if(mysqli_query("GRANT ALL ON ".mysqli_real_escape_string($link, $db_config['database_name']).".* TO '".mysqli_real_escape_string($link, $db_config['database_user'])."'@'".$db_config['database_host']."' IDENTIFIED BY '".mysqli_real_escape_string($link, $db_config['database_password'])."';", $link)) {
 				$app->log('Created MySQL user: '.$db_config['database_user'], LOGLEVEL_DEBUG);
 			} else {
-				$app->log('Unable to create database user'.$db_config['database_user'].' '.mysql_error($link), LOGLEVEL_ERROR);
+				$app->log('Unable to create database user'.$db_config['database_user'].' '.mysqli_error($link), LOGLEVEL_ERROR);
 			}
 
-			mysql_query("FLUSH PRIVILEGES;", $link);
-			mysql_close($link);
+			mysqli_query($link, "FLUSH PRIVILEGES;");
+			mysqli_close($link);
 
 		}
 
-- 
GitLab