From 353074850eb9bec4b651a578ae35c820b295d8b9 Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 3 May 2017 19:22:44 +0000 Subject: [PATCH] It is now possible to connect to a db server with host:port --- include/dba.php | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/include/dba.php b/include/dba.php index 8cbad876f5..2e89ca410d 100644 --- a/include/dba.php +++ b/include/dba.php @@ -25,11 +25,20 @@ class dba { private static $dbo; private static $relation = array(); - function __construct($server, $user, $pass, $db, $install = false) { + function __construct($serveraddr, $user, $pass, $db, $install = false) { $a = get_app(); $stamp1 = microtime(true); + $serveraddr = trim($serveraddr); + + $serverdata = explode(':', $serveraddr); + $server = $serverdata[0]; + + if (count($serverdata) > 1) { + $port = trim($serverdata[1]); + } + $server = trim($server); $user = trim($user); $pass = trim($pass); @@ -55,6 +64,11 @@ class dba { if (class_exists('\PDO') && in_array('mysql', PDO::getAvailableDrivers())) { $this->driver = 'pdo'; $connect = "mysql:host=".$server.";dbname=".$db; + + if (isset($port)) { + $connect .= ";port=".$port; + } + if (isset($a->config["system"]["db_charset"])) { $connect .= ";charset=".$a->config["system"]["db_charset"]; } @@ -64,7 +78,7 @@ class dba { } } elseif (class_exists('mysqli')) { $this->driver = 'mysqli'; - $this->db = @new mysqli($server,$user,$pass,$db); + $this->db = @new mysqli($server, $user, $pass, $db, $port); if (!mysqli_connect_errno()) { $this->connected = true; @@ -74,8 +88,8 @@ class dba { } } elseif (function_exists('mysql_connect')) { $this->driver = 'mysql'; - $this->db = mysql_connect($server,$user,$pass); - if ($this->db && mysql_select_db($db,$this->db)) { + $this->db = mysql_connect($serveraddr, $user, $pass); + if ($this->db && mysql_select_db($db, $this->db)) { $this->connected = true; if (isset($a->config["system"]["db_charset"])) { @@ -553,9 +567,10 @@ class dba { $values[] = &$args[$param]; } - array_unshift($values, $params); - - call_user_func_array(array($stmt, 'bind_param'), $values); + if (count($values) > 0) { + array_unshift($values, $params); + call_user_func_array(array($stmt, 'bind_param'), $values); + } if (!$stmt->execute()) { self::$dbo->error = self::$dbo->db->error; -- 2.39.5