Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CRM-20768 - Install UI - Accept mysql port #10553

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 34 additions & 10 deletions install/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,30 @@ public function checkdatabase($databaseConfig, $dbName) {
}
}

/**
* Connect via mysqli.
*
* This is exactly the same as mysqli_connect(), except that it accepts
* the port as part of the `$host`.
*
* @param $host
* @param $username
* @param $password
* @param string $database
* @return \mysqli
*/
protected function connect($host, $username, $password, $database = '') {
$hostParts = explode(':', $host);
if (count($hostParts) > 1) {
list ($host, $port) = $hostParts;
}
else {
$port = '';
}
$conn = @mysqli_connect($host, $username, $password, $database, $port);
return $conn;
}

/**
* Check everything except the database.
*/
Expand Down Expand Up @@ -950,7 +974,7 @@ public function requireApacheModule($moduleName, $testDetails) {
*/
public function requireMysqlConnection($server, $username, $password, $testDetails) {
$this->testing($testDetails);
$this->conn = @mysqli_connect($server, $username, $password);
$this->conn = $this->connect($server, $username, $password);

if ($this->conn) {
return TRUE;
Expand All @@ -967,7 +991,7 @@ public function requireMysqlConnection($server, $username, $password, $testDetai
*/
public function requireMySQLServer($server, $testDetails) {
$this->testing($testDetails);
$conn = @mysqli_connect($server, NULL, NULL);
$conn = $this->connect($server, NULL, NULL);

if ($conn || mysqli_connect_errno() < 2000) {
return TRUE;
Expand Down Expand Up @@ -1012,7 +1036,7 @@ public function requireMySQLVersion($version, $testDetails) {
*/
public function requireMySQLInnoDB($server, $username, $password, $database, $testDetails) {
$this->testing($testDetails);
$conn = @mysqli_connect($server, $username, $password);
$conn = $this->connect($server, $username, $password);
if (!$conn) {
$testDetails[2] .= ' ' . ts("Could not determine if MySQL has InnoDB support. Assuming no.");
$this->error($testDetails);
Expand Down Expand Up @@ -1047,7 +1071,7 @@ public function requireMySQLInnoDB($server, $username, $password, $database, $te
*/
public function requireMySQLTempTables($server, $username, $password, $database, $testDetails) {
$this->testing($testDetails);
$conn = @mysqli_connect($server, $username, $password);
$conn = $this->connect($server, $username, $password);
if (!$conn) {
$testDetails[2] = ts('Could not login to the database.');
$this->error($testDetails);
Expand Down Expand Up @@ -1077,7 +1101,7 @@ public function requireMySQLTempTables($server, $username, $password, $database,
*/
public function requireMySQLTrigger($server, $username, $password, $database, $testDetails) {
$this->testing($testDetails);
$conn = @mysqli_connect($server, $username, $password);
$conn = $this->connect($server, $username, $password);
if (!$conn) {
$testDetails[2] = ts('Could not login to the database.');
$this->error($testDetails);
Expand Down Expand Up @@ -1117,7 +1141,7 @@ public function requireMySQLTrigger($server, $username, $password, $database, $t
*/
public function requireMySQLLockTables($server, $username, $password, $database, $testDetails) {
$this->testing($testDetails);
$conn = @mysqli_connect($server, $username, $password);
$conn = $this->connect($server, $username, $password);
if (!$conn) {
$testDetails[2] = ts('Could not connect to the database server.');
$this->error($testDetails);
Expand Down Expand Up @@ -1164,7 +1188,7 @@ public function requireMySQLLockTables($server, $username, $password, $database,
*/
public function requireMySQLAutoIncrementIncrementOne($server, $username, $password, $testDetails) {
$this->testing($testDetails);
$conn = @mysqli_connect($server, $username, $password);
$conn = $this->connect($server, $username, $password);
if (!$conn) {
$testDetails[2] = ts('Could not connect to the database server.');
$this->error($testDetails);
Expand Down Expand Up @@ -1198,7 +1222,7 @@ public function requireMySQLAutoIncrementIncrementOne($server, $username, $passw
*/
public function requireMySQLThreadStack($server, $username, $password, $database, $minValueKB, $testDetails) {
$this->testing($testDetails);
$conn = @mysqli_connect($server, $username, $password);
$conn = $this->connect($server, $username, $password);
if (!$conn) {
$testDetails[2] = ts('Could not connect to the database server.');
$this->error($testDetails);
Expand Down Expand Up @@ -1242,7 +1266,7 @@ public function requireDatabaseOrCreatePermissions(
$onlyRequire = FALSE
) {
$this->testing($testDetails);
$conn = @mysqli_connect($server, $username, $password);
$conn = $this->connect($server, $username, $password);

$okay = NULL;
if (@mysqli_select_db($conn, $database)) {
Expand Down Expand Up @@ -1381,7 +1405,7 @@ class Installer extends InstallRequirements {
* @param $database
*/
public function createDatabaseIfNotExists($server, $username, $password, $database) {
$conn = @mysqli_connect($server, $username, $password);
$conn = $this->connect($server, $username, $password);

if (@mysqli_select_db($conn, $database)) {
// skip if database already present
Expand Down