]> git.mxchange.org Git - friendica.git/commitdiff
more defensive measures against failed or lost DB
authorFriendika <info@friendika.com>
Tue, 11 Jan 2011 04:14:19 +0000 (20:14 -0800)
committerFriendika <info@friendika.com>
Tue, 11 Jan 2011 04:14:19 +0000 (20:14 -0800)
include/dba.php

index 98823df3ae06563fe9e5288f064adf89a2bae896..e58abb1a1210e29e3450fe3c5c2ca995ecffdce6 100644 (file)
@@ -46,7 +46,7 @@ class dba {
                        elseif($result === true)
                                $mesg = 'true';
                        else
-                               $mesg = $result->num_rows.' results' . EOL;
+                               $mesg = $result->num_rows . ' results' . EOL;
         
                        $str =  'SQL = ' . printable($sql) . EOL . 'SQL returned ' . $mesg . EOL;
 
@@ -132,11 +132,29 @@ function q($sql) {
        global $db;
        $args = func_get_args();
        unset($args[0]);
-       $ret = $db->q(vsprintf($sql,$args));
-       return $ret;
+
+       if($db) {
+               $ret = $db->q(vsprintf($sql,$args));
+               return $ret;
+       }
+
+       /**
+        *
+        * This will happen occasionally trying to store the 
+        * session data after abnormal program termination 
+        *
+        */
+
+       logger('dba: no database: ' . print_r($args,true));
+       return false; 
+
 }}
 
-// raw db query, no arguments
+/**
+ *
+ * Raw db query, no arguments
+ *
+ */
 
 if(! function_exists('dbq')) { 
 function dbq($sql) {