X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2Fdba.php;h=86a3762b44f041945891eca407e5e31269fd7b77;hb=b50769b6d09549e1641bab1813087fd928602129;hp=3a16c187c7ec81b47085d894d169c047e18b7cd6;hpb=7d531afd00de35ef55d0cc5caa63242765341dae;p=friendica.git diff --git a/include/dba.php b/include/dba.php index 3a16c187c7..86a3762b44 100644 --- a/include/dba.php +++ b/include/dba.php @@ -1,4 +1,5 @@ connected = true; } + if (isset($a->config["system"]["db_charset"])) + $this->db->set_charset($a->config["system"]["db_charset"]); } else { $this->mysqli = false; @@ -72,6 +75,8 @@ class dba { if($this->db && mysql_select_db($db,$this->db)) { $this->connected = true; } + if (isset($a->config["system"]["db_charset"])) + mysql_set_charset($a->config["system"]["db_charset"], $this->db); } if(! $this->connected) { $this->db = null; @@ -86,6 +91,23 @@ class dba { return $this->db; } + /** + * @brief Returns the MySQL server version string + * + * This function discriminate between the deprecated mysql API and the current + * object-oriented mysqli API. Example of returned string: 5.5.46-0+deb8u1 + * + * @return string + */ + public function server_info() { + if ($this->mysqli) { + $return = $this->db->server_info; + } else { + $return = mysql_get_server_info($this->db); + } + return $return; + } + public function q($sql, $onlyquery = false) { global $a; @@ -94,6 +116,14 @@ class dba { $this->error = ''; + // Check the connection (This can reconnect the connection - if configured) + if ($this->mysqli) + $connected = $this->db->ping(); + else + $connected = mysql_ping($this->db); + + $connstr = ($connected ? "Connected": "Disonnected"); + $stamp1 = microtime(true); if($this->mysqli) @@ -106,6 +136,9 @@ class dba { $a->save_timestamp($stamp1, "database"); + if (strtolower(substr($sql, 0, 6)) != "select") + $a->save_timestamp($stamp1, "database_write"); + if(x($a->config,'system') && x($a->config['system'],'db_log')) { if (($duration > $a->config["system"]["db_loglimit"])) { $duration = round($duration, 3); @@ -118,14 +151,17 @@ class dba { } if($this->mysqli) { - if($this->db->errno) + if($this->db->errno) { $this->error = $this->db->error; + $this->errorno = $this->db->errno; + } + } elseif(mysql_errno($this->db)) { + $this->error = mysql_error($this->db); + $this->errorno = mysql_errno($this->db); } - elseif(mysql_errno($this->db)) - $this->error = mysql_error($this->db); if(strlen($this->error)) { - logger('dba: ' . $this->error); + logger('DB Error ('.$connstr.') '.$this->errorno.': '.$this->error); } if($this->debug) { @@ -230,14 +266,13 @@ class dba { } } - /** - * Checks if $array is a filled array with at least one entry. - * - * @param $array mixed A filled array with at least one entry - * @return Whether $array is a filled array - */ - public function is_result ($array) { - return (is_array($array) && count($array) > 0); + function connected() { + if ($this->mysqli) + $connected = $this->db->ping(); + else + $connected = mysql_ping($this->db); + + return $connected; } function __destruct() {