From 41ba9e6820458d66cd70668e9c34bcc592dbf9d6 Mon Sep 17 00:00:00 2001 From: Nightfly Date: Wed, 9 Jun 2021 19:18:30 +0300 Subject: [PATCH] fast and dirty fix of bobrocorrupted DbConnect class --- api/libs/api.dbconnect.php | 46 +++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/api/libs/api.dbconnect.php b/api/libs/api.dbconnect.php index 3798728a1..8013271b2 100644 --- a/api/libs/api.dbconnect.php +++ b/api/libs/api.dbconnect.php @@ -18,11 +18,17 @@ class DbConnect { var $error_reporting = false; public function __construct($host, $user, $password, $database, $error_reporting = true, $persistent = false, $port = 3306) { - $dbport = (empty($port) ? 3306 : $port); + $this->dbport = (empty($port)) ? 3306 : $port; - if (!ispos($host, ':')) { - $this->host = $host . ':' . $dbport; + //we can use custom port as :port in old mysql connection method + if (extension_loaded('mysql')) { + if (!ispos($host, ':')) { + $this->host = $host . ':' . $this->dbport; + } else { + $this->host = $host; + } } else { + //mysqli use separate parameter port on connection $this->host = $host; } @@ -34,7 +40,7 @@ public function __construct($host, $user, $password, $database, $error_reporting } public function open() { - if (extension_loaded('mysql')) { + if (extension_loaded('mysql')) { if ($this->persistent) { $func = 'mysql_pconnect'; } else { @@ -51,7 +57,7 @@ public function open() { return false; } } else { - $this->conn = new mysqli($this->host, $this->user, $this->password, $this->database); + $this->conn = new mysqli($this->host, $this->user, $this->password, $this->database, $this->dbport); if ($this->conn->connect_error) { return false; } @@ -61,25 +67,25 @@ public function open() { } public function close() { - if (extension_loaded('mysql')) { - return (@mysql_close($this->conn)); - } else { - return (@$this->conn->close()); - } + if (extension_loaded('mysql')) { + return (@mysql_close($this->conn)); + } else { + return (@$this->conn->close()); + } } public function error() { if ($this->error_reporting) { if (extension_loaded('mysql')) { return (mysql_error()); - } else { - return ($this->conn->error); - } + } else { + return ($this->conn->error); + } } } public function query($sql) { - if (extension_loaded('mysql')) { + if (extension_loaded('mysql')) { $this->result = @mysql_query($sql, $this->conn); } else { $this->result = @$this->conn->query($sql); @@ -88,7 +94,7 @@ public function query($sql) { } public function affectedrows() { - if (extension_loaded('mysql')) { + if (extension_loaded('mysql')) { return(@mysql_affected_rows($this->conn)); } else { return(@$this->conn->affected_rows); @@ -96,7 +102,7 @@ public function affectedrows() { } public function numrows() { - if (extension_loaded('mysql')) { + if (extension_loaded('mysql')) { return(@mysql_num_rows($this->result)); } else { return(@$this->conn->num_rows); @@ -104,7 +110,7 @@ public function numrows() { } public function fetchobject() { - if (extension_loaded('mysql')) { + if (extension_loaded('mysql')) { return(@mysql_fetch_object($this->result)); } else { return($result = @$this->result->fetch_object()); @@ -112,7 +118,7 @@ public function fetchobject() { } public function fetcharray() { - if (extension_loaded('mysql')) { + if (extension_loaded('mysql')) { return(mysql_fetch_array($this->result)); } else { return($result = @$this->result->fetch_array(MYSQLI_BOTH)); @@ -120,7 +126,7 @@ public function fetcharray() { } public function fetchassoc() { - if (extension_loaded('mysql')) { + if (extension_loaded('mysql')) { return(@mysql_fetch_assoc($this->result)); } else { return($result = @$this->result->fetch_assoc()); @@ -128,7 +134,7 @@ public function fetchassoc() { } public function freeresult() { - if (extension_loaded('mysql')) { + if (extension_loaded('mysql')) { return(@mysql_free_result($this->result)); } else { return(@$this->result->free());