<?php
#
# GreatWebScripts http://www.GreatWebScripts.com
#
# Copyright (c)2006, GreatWebScripts . All rights reserved.
#
# No portion of this content may be copied, distributed or reproduced for any
# reason without the express written consent of the owner. Federal copyright
# law prohibits unauthorized reproduction by any means and imposes severe fines
# for violation.
#
#
# $RCSfile: hacktrap_db_inc.php,v $ $Revision: 1.2 $ $Date: 2008-01-25 22:17:02-05 $
#
if ( !defined('GWS_GUARD') ) {header('HTTP/1.0 404 not found');exit;};
// Database Parameters
include ("hacktrap_config.php");
// SQL codes
define('TRANSACTION_NONE', 0);
define('TRANSACTION_BEGIN', 1);
define('TRANSACTION_END', 3);
//
// Select and load proper DB access package
//
switch($HACKTRAP_DB)
{
case 'mysql':
include(DB_DIR . 'db/mysql.php');
break;
case 'mysql3':
include(DB_DIR . 'db/mysql3.php');
break;
case 'postgres':
include(DB_DIR . 'db/postgres.php');
break;
case 'mssql':
include(DB_DIR . 'db/mssql.php');
break;
case 'mssql-odbc':
include(DB_DIR . 'db/mssql-odbc.php');
break;
default;
die ("Unknown Database Type: " . $HACKTRAP_DB);
break;
} // end switch
//
// DBtime returns a string formatted for the timestamp
//
define ("NOW", 0);
define ("MIDNITE", 1);
function DBtime ($time=0, $timeframe=NOW)
{
$oneday = 3600 * 24; // seconds in one day
// If no time supplied use current time
if ($time == 0) $time = time();
// Check if midnite requested: this makes it midnite in the local timezone,
// but in the server time
if ($timeframe == MIDNITE)
$time = floor ($time / $oneday) * $oneday + // SERVER: :00:00:00
($oneday - 1) + // SERVER: :23:59:59
(SERVER_TIME_OFFSET * 3600); // convert to local
// and now format the time
$sqltime = strftime ("%Y-%m-%d %H:%M:%S", $time);
return $sqltime;
} // end DBtime
// //
// Generic Database Functions //
// //
//
// Formats a DB Error into a string for display
//
function DbErrorString ()
{
global $hacktrap_db;
$errorarray = $hacktrap_db->sql_error ();
return ("(#{$errorarray ['code']}) :: {$errorarray ['message']} <br>");
} // end DbErrorString
function DbEscapeString ($sql)
{
global $hacktrap_db;
// Check for magic quotes
if (get_magic_quotes_gpc()) $retsql = stripslashes ($sql);
else $retsql = $sql;
// Now down to the specific database
$retsql = $hacktrap_db->escape_string ($retsql);
return $retsql;
} // end DbEscapeString
?>