From 393896a7010bf2da19674aa6a63a693a0d800233 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Thu, 12 Nov 2009 14:42:37 -0800 Subject: Initialize the database config with the port number if it is specified. Also set it up so the mysqli constructor will split it into host and port for the call to the mysqli constructor. Fixes ticket: #780 --- installer/cli.php | 2 +- installer/database_config.php | 2 +- installer/installer.php | 6 ++++-- installer/web.php | 1 + 4 files changed, 7 insertions(+), 4 deletions(-) (limited to 'installer') diff --git a/installer/cli.php b/installer/cli.php index 182c3d26..f736ffcb 100644 --- a/installer/cli.php +++ b/installer/cli.php @@ -95,7 +95,7 @@ function parse_cli_params() { $config["dbname"] = $argv[++$i]; break; case "-h": - $config["host"] = $argv[++$i]; + list ($config["host"], $config["port"]) = explode(":", $argv[++$i]); break; case "-u": $config["user"] = $argv[++$i]; diff --git a/installer/database_config.php b/installer/database_config.php index 0f04b95c..8abf35e7 100644 --- a/installer/database_config.php +++ b/installer/database_config.php @@ -33,7 +33,7 @@ $config['default'] = array( 'user' => '', 'pass' => '', 'host' => '', - 'port' => false, + 'port' => '' false, 'socket' => false, 'database' => '' ), diff --git a/installer/installer.php b/installer/installer.php index 70afc440..3b1716e2 100644 --- a/installer/installer.php +++ b/installer/installer.php @@ -77,7 +77,8 @@ class installer { // counterparts. if (!function_exists("mysql_query")) { function mysql_connect($host, $user, $pass) { - installer::$mysqli = new mysqli($host, $user, $pass); + list ($host, $port) = explode(":", $host); + installer::$mysqli = new mysqli($host, $user, $pass, $port); // http://php.net/manual/en/mysqli.connect.php says to use mysqli_connect_error() instead of // $mysqli->connect_error because of bugs before PHP 5.2.9 $error = mysqli_connect_error(); @@ -97,7 +98,8 @@ class installer { } } - return @mysql_connect($config["host"], $config["user"], $config["password"]); + $host = empty($config["port"]) ? $config['host'] : "{$config['host']}:{$config['port']}"; + return @mysql_connect($host, $config["user"], $config["password"]); } static function select_db($config) { diff --git a/installer/web.php b/installer/web.php index c46f072a..65233b31 100644 --- a/installer/web.php +++ b/installer/web.php @@ -38,6 +38,7 @@ if (installer::already_installed()) { "dbname" => $_POST["dbname"], "prefix" => $_POST["prefix"], "type" => function_exists("mysqli_set_charset") ? "mysqli" : "mysql"); + list ($config["host"], $config["port"]) = explode(":", $config["host"]); if (!installer::connect($config)) { $content = render("invalid_db_info.html.php"); -- cgit v1.2.3