]> git.mxchange.org Git - friendica.git/blobdiff - include/dba.php
[frio] Fix code block display
[friendica.git] / include / dba.php
index b0927265be9006e24bc16e368b86763ae690bb23..86a3762b44f041945891eca407e5e31269fd7b77 100644 (file)
@@ -66,6 +66,8 @@ class dba {
                        if(! mysqli_connect_errno()) {
                                $this->connected = true;
                        }
+                       if (isset($a->config["system"]["db_charset"]))
+                               $this->db->set_charset($a->config["system"]["db_charset"]);
                }
                else {
                        $this->mysqli = false;
@@ -73,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;
@@ -87,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;
 
@@ -95,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)
@@ -122,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) {
@@ -234,6 +266,15 @@ class dba {
                }
        }
 
+       function connected() {
+               if ($this->mysqli)
+                       $connected = $this->db->ping();
+               else
+                       $connected = mysql_ping($this->db);
+
+               return $connected;
+       }
+
        function __destruct() {
                if ($this->db)
                        if($this->mysqli)