Skip to content

Commit

Permalink
Merge pull request #864 from greezybacon/issue/mysqli-local-socket
Browse files Browse the repository at this point in the history
mysqli: Allow specification of a unix socket

Reviewed-By: Peter Rotich <peter@osticket.com>
  • Loading branch information
protich committed Dec 16, 2013
2 parents d751f45 + 5910e13 commit 8cf6850
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
18 changes: 12 additions & 6 deletions include/mysqli.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,24 @@ function db_connect($host, $user, $passwd, $options = array()) {
return NULL;

$port = ini_get("mysqli.default_port");
$socket = ini_get("mysqli.default_socket");
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'
if (!strcasecmp($host, 'localhost'))
// XXX: Looks like PHP gethostbyname() is IPv4 only
$host = gethostbyname($host);
$port = (int) $port;
if ($portspec && is_numeric($portspec)) {
if (!strcasecmp($host, 'localhost'))
// XXX: Looks like PHP gethostbyname() is IPv4 only
$host = gethostbyname($host);
$port = (int) $portspec;
}
elseif ($portspec) {
$socket = $portspec;
}
}

// Connect
$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;

//Select the database, if any.
Expand Down
4 changes: 1 addition & 3 deletions setup/inc/class.installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,7 @@ function install($vars) {

// Support port number specified in the hostname with a colon (:)
list($host, $port) = explode(':', $vars['dbhost']);
if ($port && (!is_numeric($port) || !((int)$port)))
$this->errors['db'] = 'Database port number must be a number';
elseif ($port && ($port < 1 || $port > 65535))
if ($port && is_numeric($port) && ($port < 1 || $port > 65535))
$this->errors['db'] = 'Invalid database port number';

//MYSQL: Connect to the DB and check the version & database (create database if it doesn't exist!)
Expand Down

0 comments on commit 8cf6850

Please sign in to comment.