From b6ce737038f060665901da2ac720663f573f07b3 Mon Sep 17 00:00:00 2001 From: Brady Miller Date: Mon, 28 May 2018 09:42:56 -0700 Subject: [PATCH] another mysql fix (#1668) --- library/classes/Installer.class.php | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/library/classes/Installer.class.php b/library/classes/Installer.class.php index 82348f20b..d7d5d62e2 100644 --- a/library/classes/Installer.class.php +++ b/library/classes/Installer.class.php @@ -207,7 +207,13 @@ class Installer return false; } else if ($checkUser->num_rows > 0) { // the mysql user already exists, so do not need to create the user, but need to set the password - return $this->execute_sql("ALTER USER '" . $this->escapeSql($this->login) . "'@'" . $this->escapeSql($this->loginhost) . "' IDENTIFIED BY '" . $this->escapeSql($this->pass) . "'"); + // Note need to try two different methods, first is for newer mysql versions and second is for older mysql versions (if the first method fails) + $returnSql = $this->execute_sql("ALTER USER '" . $this->escapeSql($this->login) . "'@'" . $this->escapeSql($this->loginhost) . "' IDENTIFIED BY '" . $this->escapeSql($this->pass) . "'", false); + if ($returnSql === false) { + error_log("Using older mysql version method to set password for the mysql user"); + $returnSql = $this->execute_sql("SET PASSWORD FOR '" . $this->escapeSql($this->login) . "'@'" . $this->escapeSql($this->loginhost) . "' = PASSWORD('" . $this->escapeSql($this->pass) . "')"); + } + return $returnSql; } else { // the mysql user does not yet exist, so create the user return $this->execute_sql("CREATE USER '" . $this->escapeSql($this->login) . "'@'" . $this->escapeSql($this->loginhost) . "' IDENTIFIED BY '" . $this->escapeSql($this->pass) . "'"); @@ -615,7 +621,7 @@ if ($it_died != 0) { return $name; } - private function execute_sql($sql) + private function execute_sql($sql, $showError = true) { $this->error_message = ''; if (! $this->dbh) { @@ -626,9 +632,11 @@ if ($it_died != 0) { if ($results) { return $results; } else { - $error_mes = mysqli_error($this->dbh); - $this->error_message = "unable to execute SQL: '$sql' due to: " . $error_mes; - error_log("ERROR IN OPENEMR INSTALL: Unable to execute SQL: ".$sql." due to: ".$error_mes); + if ($showError) { + $error_mes = mysqli_error($this->dbh); + $this->error_message = "unable to execute SQL: '$sql' due to: " . $error_mes; + error_log("ERROR IN OPENEMR INSTALL: Unable to execute SQL: " . $sql . " due to: " . $error_mes); + } return false; } } -- 2.11.4.GIT