diff options
author | Arun Persaud <arun@nubati.net> | 2013-02-09 08:55:42 -0800 |
---|---|---|
committer | Arun Persaud <arun@nubati.net> | 2013-02-09 08:55:42 -0800 |
commit | 34745273b4e8935b4423a0db050dcd75bc672209 (patch) | |
tree | 65d07cd87ac3205bbb783af4b35f1b326461f9eb /include | |
parent | 64586775883969c933517edc541b6f5a0878bd7d (diff) | |
download | e-DoKo-34745273b4e8935b4423a0db050dcd75bc672209.tar.gz e-DoKo-34745273b4e8935b4423a0db050dcd75bc672209.tar.bz2 e-DoKo-34745273b4e8935b4423a0db050dcd75bc672209.zip |
moved php from old mysql to myslqi to make things more future proof
Diffstat (limited to 'include')
-rw-r--r-- | include/db.php | 31 | ||||
-rw-r--r-- | include/stats.php | 5 |
2 files changed, 16 insertions, 20 deletions
diff --git a/include/db.php b/include/db.php index f683beb..3be9494 100644 --- a/include/db.php +++ b/include/db.php @@ -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 */ diff --git a/include/stats.php b/include/stats.php index d72b1ef..1042c6b 100644 --- a/include/stats.php +++ b/include/stats.php @@ -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"; */ |