]> git.mxchange.org Git - friendica.git/blobdiff - include/dba.php
optimise the commented date view
[friendica.git] / include / dba.php
index b05a1cabf48b8dce79ac22609d4cea389e433062..70c27515c4499d268327285c7809183cc65a5890 100644 (file)
@@ -19,13 +19,32 @@ class dba {
        public  $connected = false;
 
        function __construct($server,$user,$pass,$db,$install = false) {
+
+               $server = trim($server);
+               $user = trim($user);
+               $pass = trim($pass);
+               $db = trim($db);
+
+               if($install) {
+                       if(strlen($server) && ($server !== 'localhost') && ($server !== '127.0.0.1')) {
+                               if(! dns_get_record($server, DNS_A + DNS_CNAME + DNS_PTR)) {
+                                       notice( sprintf( t('Cannot locate DNS info for database server \'%s\''), $server));
+                                       $this->connected = false;
+                                       $this->db = null;
+                                       return;
+                               }
+                       }
+               }
+
                $this->db = @new mysqli($server,$user,$pass,$db);
-               if((mysqli_connect_errno()) && (! $install)) {
+               if(! mysqli_connect_errno()) {
+                       $this->connected = true;
+               }
+               else {
                        $this->db = null;
-                       system_unavailable();
+                       if(! $install)
+                               system_unavailable();
                }
-               else
-                       $this->connected = true;    
        }
 
        public function getdb() {
@@ -34,7 +53,7 @@ class dba {
 
        public function q($sql) {
                
-               if(! $this->db )
+               if((! $this->db) || (! $this->connected))
                        return false;
                
                $result = @$this->db->query($sql);
@@ -59,7 +78,7 @@ class dba {
                }
                else {
 
-                       /*
+                       /**
                         * If dbfail.out exists, we will write any failed calls directly to it,
                         * regardless of any logging that may or may nor be in effect.
                         * These usually indicate SQL syntax errors that need to be resolved.
@@ -92,7 +111,8 @@ class dba {
        }
 
        public function escape($str) {
-               return @$this->db->real_escape_string($str);
+               if($this->db && $this->connected)
+                       return @$this->db->real_escape_string($str);
        }
 
        function __destruct() {
@@ -192,4 +212,6 @@ function dbesc_array(&$arr) {
        if(is_array($arr) && count($arr)) {
                array_walk($arr,'dbesc_array_cb');
        }
-}}             
\ No newline at end of file
+}}             
+
+