<?php
-/* Copyright 2006, 2007, 2008, 2009, 2010, 2011, 2012 Arun Persaud <arun@nubati.net>
+/* Copyright 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Arun Persaud <arun@nubati.net>
*
* This file is part of e-DoKo.
*
$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;
};
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;
}
/* use Mysql in the background */
function DB_query($query)
{
+ global $DB;
/* debug/optimize the database
$time = microtime();
- $return = mysql_query($query);
- $time = $time - microtime();
+ $return = $DB->query($query);
+ $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);
};
return $return;
*/
- return mysql_query($query);
+ return $DB->query($query);
}
function DB_fetch_array($result)
{
- return mysql_fetch_array($result,MYSQL_NUM);
+ if($result)
+ return $result->fetch_array(MYSQLI_NUM);
+ else
+ return NULL;
}
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 */
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)."");
switch($pref[0])
{
case 'cardset':
- /* licence only valid until then */
- if($pref[1]=='altenburg' && (time()-strtotime( '2012-12-31 23:59:59')<0) )
- $PREF['cardset']='altenburg';
break;
case 'email':