allow using socket to connect to mysql split the socket from port if hostname contains colon this also allows $port to be just path to socket (not-numeric) localhost:/tmp/sock inspired by: http://bugs.cacti.net/view.php?id=425 note: this socket works for mysqli driver only: http://phplens.com/lens/adodb/docs-adodb.htm --- cacti-0.8.7i-PIA-3.1/lib/database.php~ 2011-12-12 03:56:06.000000000 +0200 +++ cacti-0.8.7i-PIA-3.1/lib/database.php 2012-01-24 11:18:39.563094454 +0200 @@ -34,6 +34,11 @@ function db_connect_real($host, $user, $pass, $db_name, $db_type, $port = "3306", $db_ssl = false, $retries = 20) { global $cnn_id; + // convert hostname:port to hostname and port + if (strchr($host, ':')) { + list($host, $port) = explode(':', $host, 2); + } + $i = 0; $dsn = "$db_type://" . rawurlencode($user) . ":" . rawurlencode($pass) . "@" . rawurlencode($host) . "/" . rawurlencode($db_name) . "?persist"; @@ -43,7 +48,10 @@ $dsn .= "&clientflags=" . MYSQLI_CLIENT_SSL; } - if ($port != "3306") { + // socket supported for mysqli only, not mysql + if ($port && !is_numeric($port)) { + $dsn .= "&socket=" . $port; + } elseif ($port != "3306") { $dsn .= "&port=" . $port; }