$b_int) {
return ($a_int-$b_int)+($a_micro-$b_micro);
} elseif ($a_int==$b_int) {
if ($a_micro>$b_micro) {
return ($a_int-$b_int)+($a_micro-$b_micro);
} elseif ($a_micro<$b_micro) {
return ($b_int-$a_int)+($b_micro-$a_micro);
} else {
return 0;
}
} else { // $a_int<$b_int
return ($b_int-$a_int)+($b_micro-$a_micro);
}
}
//! Cerberus database object
/*!
Database encapsulation object and functions.
*/
class cer_Database
{
var $db; //!< Database connection handler
function getInstance() {
static $instance = NULL;
if($instance == NULL) {
$instance = new cer_Database();
$instance->connect();
}
return $instance;
}
//! Connect and log in to the database server
/*!
Authenticate with the database server. Reads server, user and password from
the "DB_" constants in the site.config.php file
\return Boolean true/false of success or failure.
*/
function connect($dbs="",$dbn="",$dbu="",$dbp="",$dbplat="mysql")
{
// [JAS]: If no alternative database is specified, use the default from site.config.php
if($dbs=="")
{
$this->db = &ADONewConnection(DB_PLATFORM);
@$this->db->connect(DB_SERVER, DB_USER, DB_PASS, DB_NAME)
or die("Cerberus [ERROR]: Could not connect to database. Check your config.php DB_* settings.
Reason: (" . mysql_error() . ")");
}
else
{
$this->db = &ADONewConnection($dbplat);
$this->db->connect($dbs, $dbu, $dbp, $dbn);
}
if($this->db) { return true; } else { return false; }
}
function close() {
$this->db->close();
}
//! Execute a SQL query
/*!
Run a SQL query against the current database. If running in \e DEBUG_MODE
then all queries will be output directly to the screen in addition to being
executed.
\param $sqlString SQL \c string to be executed
\param $return_asoc Return an associative array result set (if false, returns numerical array)
\return \c Resultset object.
*/
function query($sqlString,$return_assoc=true)
{
$cfg = CerConfiguration::getInstance();
if($cfg->settings["debug_mode"]) {
$time_start = microtime();
}
//$res = mysql_query($sqlString,$this->db) or die ("Cerberus [ERROR]: Could not query database. (" . mysql_error() . ")");
if($return_assoc === true) $this->db->SetFetchMode(ADODB_FETCH_ASSOC);
else $this->db->SetFetchMode(ADODB_FETCH_NUM);
$res = $this->db->Execute($sqlString);
if($cfg->settings["debug_mode"]) {
$time_end = microtime();
$query_time = microtime_diff($time_end,$time_start) * 1000; // convert secs to millisecs
echo "[CERBERUS QUERY]: " . $sqlString . " (Ran: " . sprintf("%0.3f",$query_time) . "ms)