Skip to content

Commit

Permalink
fast and dirty fix of bobrocorrupted DbConnect class
Browse files Browse the repository at this point in the history
  • Loading branch information
nightflyza committed Jun 9, 2021
1 parent d0b8bf4 commit 41ba9e6
Showing 1 changed file with 26 additions and 20 deletions.
46 changes: 26 additions & 20 deletions api/libs/api.dbconnect.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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 {
Expand All @@ -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;
}
Expand All @@ -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);
Expand All @@ -88,47 +94,47 @@ 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);
}
}

public function numrows() {
if (extension_loaded('mysql')) {
if (extension_loaded('mysql')) {
return(@mysql_num_rows($this->result));
} else {
return(@$this->conn->num_rows);
}
}

public function fetchobject() {
if (extension_loaded('mysql')) {
if (extension_loaded('mysql')) {
return(@mysql_fetch_object($this->result));
} else {
return($result = @$this->result->fetch_object());
}
}

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));
}
}

public function fetchassoc() {
if (extension_loaded('mysql')) {
if (extension_loaded('mysql')) {
return(@mysql_fetch_assoc($this->result));
} else {
return($result = @$this->result->fetch_assoc());
}
}

public function freeresult() {
if (extension_loaded('mysql')) {
if (extension_loaded('mysql')) {
return(@mysql_free_result($this->result));
} else {
return(@$this->result->free());
Expand Down

0 comments on commit 41ba9e6

Please sign in to comment.