From d8d734265e62b5a8970541f5b6d150bdb52542da Mon Sep 17 00:00:00 2001 From: plegall Date: Fri, 12 Apr 2013 21:56:58 +0000 Subject: bug 2865: mysqli can now handle socket and specific port number git-svn-id: http://piwigo.org/svn/branches/2.5@22181 68402e56-0260-453c-a942-63ccdbb3a9ee --- include/dblayer/functions_mysqli.inc.php | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/include/dblayer/functions_mysqli.inc.php b/include/dblayer/functions_mysqli.inc.php index 2c7f0c6af..9de75a6e5 100644 --- a/include/dblayer/functions_mysqli.inc.php +++ b/include/dblayer/functions_mysqli.inc.php @@ -36,8 +36,29 @@ define('DB_RANDOM_FUNCTION', 'RAND'); function pwg_db_connect($host, $user, $password, $database) { global $mysqli; + + // exemples of $host + // + // $host = localhost + // $host = 1.2.3.4:3405 + // $host = /path/to/socket + + $port = null; + $socket = null; + + if (strpos($host, '/') === 0) + { + $host = null; + $socket = $host; + } + elseif (strpos($host, ':') !== false) + { + list($host, $port) = explode(':', $host); + } + + $dbname = null; - $mysqli = new mysqli($host, $user, $password); + $mysqli = new mysqli($host, $user, $password, $dbname, $port, $socket); if (mysqli_connect_error()) { throw new Exception("Can't connect to server"); -- cgit v1.2.3