From 9043c4bfd4a243e99d91846c15e439beb46629f0 Mon Sep 17 00:00:00 2001 From: Seamus Lee Date: Tue, 28 Feb 2017 20:40:19 +1100 Subject: [PATCH] CRM-19835 Use host rather than server and put in port if supplied --- Civi/Install/Requirements.php | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/Civi/Install/Requirements.php b/Civi/Install/Requirements.php index 5677d970a9..420b0eb40a 100644 --- a/Civi/Install/Requirements.php +++ b/Civi/Install/Requirements.php @@ -101,6 +101,17 @@ class Requirements { return $errors; } + /** + * Generates a mysql connection + * + * @param $db_confic array + * @return object mysqli connection + */ + protected function connect($db_config) { + $conn = @mysqli_connect($db_config['host'], $db_config['username'], $db_config['password'], $db_config['database'], isset($db_config['port']) ? $db_config['port'] : NULL); + return $donn; + } + /** * Check configured php Memory. * @return array @@ -227,8 +238,7 @@ class Requirements { 'details' => "Connected", ); - $host = isset($db_config['server']) ? $db_config['server'] : $db_config['host']; - $conn = @mysqli_connect($host, $db_config['username'], $db_config['password']); + $conn = $this->connect($db_config); if (!$conn) { $results['details'] = mysqli_connect_error(); @@ -257,8 +267,7 @@ class Requirements { 'severity' => $this::REQUIREMENT_OK, ); - $host = isset($db_config['server']) ? $db_config['server'] : $db_config['host']; - $conn = @mysqli_connect($host, $db_config['username'], $db_config['password']); + $conn = $this->connect($db_config); if (!$conn || !($info = mysqli_get_server_info($conn))) { $results['severity'] = $this::REQUIREMENT_WARNING; $results['details'] = "Cannot determine the version of MySQL installed. Please ensure at least version {$min} is installed."; @@ -287,7 +296,7 @@ class Requirements { 'details' => 'Could not determine if MySQL has InnoDB support. Assuming none.', ); - $conn = @mysqli_connect($db_config['host'], $db_config['username'], $db_config['password']); + $conn = $this->connect($db_config); if (!$conn) { return $results; } @@ -322,7 +331,7 @@ class Requirements { 'details' => 'MySQL server supports temporary tables', ); - $conn = @mysqli_connect($db_config['host'], $db_config['username'], $db_config['password']); + $conn = $this->connect($db_config); if (!$conn) { $results['severity'] = $this::REQUIREMENT_ERROR; $results['details'] = "Could not connect to database"; @@ -358,7 +367,7 @@ class Requirements { 'details' => 'Database supports MySQL triggers', ); - $conn = @mysqli_connect($db_config['host'], $db_config['username'], $db_config['password']); + $conn = $this->connect($db_config); if (!$conn) { $results['severity'] = $this::REQUIREMENT_ERROR; $results['details'] = 'Could not connect to database'; @@ -403,7 +412,7 @@ class Requirements { 'details' => 'MySQL server auto_increment_increment is 1', ); - $conn = @mysqli_connect($db_config['host'], $db_config['username'], $db_config['password']); + $conn = $this->connect($db_config); if (!$conn) { $results['severity'] = $this::REQUIREMENT_ERROR; $results['details'] = 'Could not connect to database'; @@ -439,8 +448,7 @@ class Requirements { 'details' => 'MySQL thread_stack is OK', ); - $host = isset($db_config['server']) ? $db_config['server'] : $db_config['host']; - $conn = @mysqli_connect($host, $db_config['username'], $db_config['password']); + $conn = $this->connect($db_config); if (!$conn) { $results['severity'] = $this::REQUIREMENT_ERROR; $results['details'] = 'Could not connect to database'; @@ -481,8 +489,7 @@ class Requirements { 'details' => 'Can successfully lock and unlock tables', ); - $host = isset($db_config['server']) ? $db_config['server'] : $db_config['host']; - $conn = @mysqli_connect($host, $db_config['username'], $db_config['password']); + $conn = $this->connect($db_config); if (!$conn) { $results['severity'] = $this::REQUIREMENT_ERROR; $results['details'] = 'Could not connect to database'; -- 2.25.1