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