BUGFIX: mysql needs to return NULL when nothing was found
[e-DoKo.git] / include / db.php
index 3be949468495aa373c2da51c051ee10e66d2bbb7..493b93dd08862953711b8a3b0cb7bf294e36a835 100644 (file)
@@ -88,13 +88,21 @@ function DB_query($query)
   /* debug/optimize the database
   $time = microtime();
   $return = $DB->query($query);
-  $time = $time - microtime();
+  $time = microtime() - $time;
 
-  if($time > 0.05) // this way we can find only the long ones
+  if($time > 0.15) // this way we can find only the long ones
   {
-    $logfile=fopen('/tmp/DBlog.log','a+');
-    fwrite($logfile,"EXPLAIN $query ;\n");
-    fwrite($logfile,"time of above query: $time\n");
+    $logfile=fopen('DBlog.log','a+');
+    fwrite($logfile,"time of query: $time\n");
+    fwrite($logfile,wordwrap("  EXPLAIN $query ;\n", 60, "\n         "));
+
+    $result = "";
+    $queryresult  = mysql_query("EXPLAIN $query ;");
+    if( $queryresult )
+      while($row = DB_fetch_array($queryresult))
+        $result  .= "   |".implode("|",$row)."|\n";
+
+    fwrite($logfile,"$result \n\n");
     fclose($logfile);
   };
 
@@ -106,7 +114,10 @@ function DB_query($query)
 
 function DB_fetch_array($result)
 {
-  return $result->fetch_array(MYSQLI_NUM);
+  if($result)
+    return $result->fetch_array(MYSQLI_NUM);
+  else
+    return NULL;
 }
 
 function DB_insert_id()
@@ -141,16 +152,6 @@ function DB_get_version()
   return $version[0];
 }
 
-function DB_get_passwd_by_name($name)
-{
-  $r = DB_query_array("SELECT password FROM User WHERE fullname=".DB_quote_smart($name)."");
-
-  if($r)
-    return $r[0];
-  else
-    return "";
-}
-
 function DB_get_passwd_by_userid($id)
 {
   $r = DB_query_array("SELECT password FROM User WHERE id=".DB_quote_smart($id)."");