moved php from old mysql to myslqi to make things more future proof
authorArun Persaud <arun@nubati.net>
Sat, 9 Feb 2013 16:55:42 +0000 (08:55 -0800)
committerArun Persaud <arun@nubati.net>
Sat, 9 Feb 2013 16:55:42 +0000 (08:55 -0800)
include/db.php
include/stats.php

index f683beba29402686e4e93a057139cd63787b0bd3..3be949468495aa373c2da51c051ee10e66d2bbb7 100644 (file)
@@ -33,14 +33,10 @@ function DB_open()
   $version_needed = 5;
 
   global $DB,$DB_user,$DB_host,$DB_database,$DB_password;
-  $DB = @mysql_connect($DB_host,$DB_user, $DB_password);
-  if ( $DB )
+  $DB = new mysqli($DB_host,$DB_user, $DB_password, $DB_database);
+  if ( $DB->connect_errno )
     {
-      mysql_select_db($DB_database) or die('Error: Could not select database');
-    }
-  else
-    {
-      echo mysql_errno() . ": " . mysql_error(). "\n";
+      echo "Failed to connect to Mysql ".$DB->connect_error." (".$DB->connect_errno.")\n";
       return -1;
     };
 
@@ -54,19 +50,21 @@ function DB_open()
 function DB_close()
 {
   global $DB;
-  mysql_close($DB);
+  $DB->close();
   return;
 }
 
 function DB_quote_smart($value)
 {
+    global $DB;
     /* Stripslashes */
     if (get_magic_quotes_gpc()) {
         $value = stripslashes($value);
     }
     /* Quote if not a number or a numeric string */
     if (!is_numeric($value)) {
-        $value = "'" . mysql_real_escape_string($value) . "'";
+        $value = "'" . $DB->real_escape_string($value) . "'";
+       $value = addcslashes($value, '%_');
     }
     return $value;
 }
@@ -86,9 +84,10 @@ function DB_test()
 /* use Mysql in the background */
 function DB_query($query)
 {
+  global $DB;
   /* debug/optimize the database
   $time = microtime();
-  $return = mysql_query($query);
+  $return = $DB->query($query);
   $time = $time - microtime();
 
   if($time > 0.05) // this way we can find only the long ones
@@ -102,22 +101,18 @@ function DB_query($query)
   return $return;
   */
 
-  return mysql_query($query);
+  return $DB->query($query);
 }
 
 function DB_fetch_array($result)
 {
-  return mysql_fetch_array($result,MYSQL_NUM);
+  return $result->fetch_array(MYSQLI_NUM);
 }
 
 function DB_insert_id()
 {
-  return mysql_insert_id();
-}
-
-function DB_num_rows($result)
-{
-  return mysql_num_rows($result);
+  global $DB;
+  return $DB->insert_id;
 }
 /* end Mysql functions */
 
index d72b1efcc70ab6bb073b172b5b7cdb259d218b75..1042c6b2fd2f1e3d91b9210f7554fe054ce512d9 100644 (file)
@@ -199,13 +199,14 @@ if( !$content = getCache("cache/stats.html",60*60*24) )
   /*
  does the party win more often if they start
 
+ global $DB;
  echo "<p>The party playing first wins in";
- $result = mysql_query("SELECT COUNT(*) from Score".
+ $result = $DB->query("SELECT COUNT(*) from Score".
  " LEFT JOIN Game ON Game.id=game_id".
  " WHERE score='againstqueens'".
  " AND Game.status='gameover'".
  " AND Game.type<>'solo'");
- while( $r = mysql_fetch_array($result,MYSQL_NUM))
+ while( $r = $result->fetch_array(MYSQLI_NUM))
  echo $r[1]." (".$r[0].") <br />\n";
  echo " games</p>\n";
   */