Instantly share code, notes, and snippets.

Embed
What would you like to do?
--- mysql.db.inc.orig 2016-04-25 09:40:40.329052075 +0200
+++ mysql.db.inc 2016-04-25 09:58:47.650099683 +0200
@@ -5,10 +5,14 @@
//Should have plug in compatibility.
function dbConnect() {
+ global $dbh;
$GLOBALS["CONNECTED_MYSQL_DB_INC"] = 1;
global $DATABASE_HOST, $DATABASE_USER, $DATABASE_PASS, $DATABASE_DB;
- $dbh = mysql_pconnect("$DATABASE_HOST","$DATABASE_USER","$DATABASE_PASS") or die("Unable to connect to SQL server: ". mysql_error());
- mysql_select_db("$DATABASE_DB",$dbh) or die("Unable to select database: ".mysql_error());
+ $dbh = mysqli_connect("$DATABASE_HOST","$DATABASE_USER","$DATABASE_PASS", "$DATABASE_DB");
+ if (mysqli_connect_errno())
+ {
+ die("Failed to connect to MySQL: " . mysqli_connect_error());
+ }
return $dbh;
}
@@ -41,36 +45,39 @@
}
function dbQuery ($statement) {
+ global $dbh;
if (!isset($GLOBALS["CONNECTED_MYSQL_DB_INC"]))
dbConnect();
//$result=@mysql_query($statement) or die("<pre>\n\nCan't perform query: " . mysql_error() . " \n\n$statement\n\n</pre>");
- $result=mysql_query($statement) or die("<pre>\n\nCan't perform query: " . mysql_error() . " \n\n$statement\n\n</pre>");
+ $result=mysqli_query($dbh, $statement) or die("<pre>\n\nCan't perform query: " . mysql_error() . " \n\n$statement\n\n</pre>");
$num_rows = dbNumRows($result);
return array($result, $num_rows);
}
function tryDbQuery ($statement) {
+ global $dbh;
if (!isset($GLOBALS["CONNECTED_MYSQL_DB_INC"]))
dbConnect();
//$result=@mysql_query($statement) or die("<pre>\n\nCan't perform query: " . mysql_error() . " \n\n$statement\n\n</pre>");
- $result=mysql_query($statement);
+ $result=mysqli_query($dbh, $statement);
$num_rows = dbNumRows($result);
return array($result, $num_rows);
}
function dbNumRows ($result) {
- return @mysql_numrows($result);
+ return @mysqli_num_rows($result);
}
function dbResult ($result,$i=-1) {
if ($i >= 0) {
- @mysql_data_seek($result,$i);
+ @mysqli_data_seek($result,$i);
}
- return mysql_fetch_array($result);
+ return mysqli_fetch_array($result);
}
function dbLastID($result) {
- return mysql_insert_id($result);
+ global $dbh;
+ return mysqli_insert_id($dbh);
}
}?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment