]> git.mxchange.org Git - friendica.git/blobdiff - include/dba.php
Merge pull request #276 from tomtom84/master
[friendica.git] / include / dba.php
old mode 100755 (executable)
new mode 100644 (file)
index 138e82b..c9f8802
@@ -75,22 +75,28 @@ class dba {
                if((! $this->db) || (! $this->connected))
                        return false;
                
+               $this->error = '';
+
                if($this->mysqli)
                        $result = @$this->db->query($sql);
                else
                        $result = @mysql_query($sql,$this->db);
 
+               if($this->mysqli) {
+                       if($this->db->errno)
+                               $this->error = $this->db->error;
+               }
+               elseif(mysql_errno($this->db))
+                               $this->error = mysql_error($this->db);  
+
+               if(strlen($this->error)) {
+                       logger('dba: ' . $this->error);
+               }
+
                if($this->debug) {
 
                        $mesg = '';
 
-                       if($this->mysqli) {
-                               if($this->db->errno)
-                                       logger('dba: ' . $this->db->error);
-                       }
-                       elseif(mysql_errno($this->db))
-                               logger('dba: ' . mysql_error($this->db));
-
                        if($result === false)
                                $mesg = 'false';
                        elseif($result === true)
@@ -102,7 +108,9 @@ class dba {
                                        $mesg = mysql_num_rows($result) . ' results' . EOL;
                        }
     
-                       $str =  'SQL = ' . printable($sql) . EOL . 'SQL returned ' . $mesg . EOL;
+                       $str =  'SQL = ' . printable($sql) . EOL . 'SQL returned ' . $mesg 
+                               . (($this->error) ? ' error: ' . $this->error : '')
+                               . EOL;
 
                        logger('dba: ' . $str );
                }
@@ -114,9 +122,9 @@ class dba {
                 */
 
                if($result === false) {
-                       logger('dba: ' . printable($sql) . ' returned false.');
+                       logger('dba: ' . printable($sql) . ' returned false.' . "\n" . $this->error);
                        if(file_exists('dbfail.out'))
-                               file_put_contents('dbfail.out', datetime_convert() . "\n" . printable($sql) . ' returned false' . "\n", FILE_APPEND);
+                               file_put_contents('dbfail.out', datetime_convert() . "\n" . printable($sql) . ' returned false' . "\n" . $this->error . "\n", FILE_APPEND);
                }
 
                if(($result === true) || ($result === false))
@@ -209,9 +217,8 @@ function q($sql) {
        if($db && $db->connected) {
                $stmt = vsprintf($sql,$args);
                if($stmt === false)
-                       logger('dba: vsprintf error: ' . print_r(debug_bracktrace(),true));
-               $ret = $db->q($stmt);
-               return $ret;
+                       logger('dba: vsprintf error: ' . print_r(debug_backtrace(),true));
+               return $db->q($stmt);
        }
 
        /**
@@ -261,6 +268,4 @@ function dbesc_array(&$arr) {
        if(is_array($arr) && count($arr)) {
                array_walk($arr,'dbesc_array_cb');
        }
-}}             
-
-
+}}