Skip to content
Snippets Groups Projects
Commit 8cf68502 authored by Peter Rotich's avatar Peter Rotich
Browse files

Merge pull request #864 from greezybacon/issue/mysqli-local-socket


mysqli: Allow specification of a unix socket

Reviewed-By: default avatarPeter Rotich <peter@osticket.com>
parents d751f452 5910e13d
Branches
Tags
No related merge requests found
...@@ -39,18 +39,24 @@ function db_connect($host, $user, $passwd, $options = array()) { ...@@ -39,18 +39,24 @@ function db_connect($host, $user, $passwd, $options = array()) {
return NULL; return NULL;
$port = ini_get("mysqli.default_port"); $port = ini_get("mysqli.default_port");
$socket = ini_get("mysqli.default_socket");
if (strpos($host, ':') !== false) { if (strpos($host, ':') !== false) {
list($host, $port) = explode(':', $host); list($host, $portspec) = explode(':', $host);
// PHP may not honor the port number if connecting to 'localhost' // PHP may not honor the port number if connecting to 'localhost'
if (!strcasecmp($host, 'localhost')) if ($portspec && is_numeric($portspec)) {
// XXX: Looks like PHP gethostbyname() is IPv4 only if (!strcasecmp($host, 'localhost'))
$host = gethostbyname($host); // XXX: Looks like PHP gethostbyname() is IPv4 only
$port = (int) $port; $host = gethostbyname($host);
$port = (int) $portspec;
}
elseif ($portspec) {
$socket = $portspec;
}
} }
// Connect // Connect
$start = microtime(true); $start = microtime(true);
if (!@$__db->real_connect($host, $user, $passwd, null, $port)) # nolint if (!@$__db->real_connect($host, $user, $passwd, null, $port, $socket)) # nolint
return NULL; return NULL;
//Select the database, if any. //Select the database, if any.
......
...@@ -81,9 +81,7 @@ class Installer extends SetupWizard { ...@@ -81,9 +81,7 @@ class Installer extends SetupWizard {
// Support port number specified in the hostname with a colon (:) // Support port number specified in the hostname with a colon (:)
list($host, $port) = explode(':', $vars['dbhost']); list($host, $port) = explode(':', $vars['dbhost']);
if ($port && (!is_numeric($port) || !((int)$port))) if ($port && is_numeric($port) && ($port < 1 || $port > 65535))
$this->errors['db'] = 'Database port number must be a number';
elseif ($port && ($port < 1 || $port > 65535))
$this->errors['db'] = 'Invalid database port number'; $this->errors['db'] = 'Invalid database port number';
//MYSQL: Connect to the DB and check the version & database (create database if it doesn't exist!) //MYSQL: Connect to the DB and check the version & database (create database if it doesn't exist!)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment