<?
/*
HPE - News Portal Engine
Copyright (C) 2000-2001 Mike Krus
This program is free software; it is distributed in the hope
that it will be useful, but WITHOUT ANY WARRANTY; without
even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE.
READ LICENSE.TXT IN THE BASE DIRECTORY FOR INFORMATION
ABOUT REDISTRIBUTING THIS SOURCE CODE
*/
// PEAR DB abstractions
require_once 'DB.php';
class HPEDBAccess {
var $dberr = "";
var $db = 0;
var $dbconfurl;
var $dbtnewssites = "HPENewsSites";
var $dbtnewsbundles = "HPENewsBundles";
var $dbtnewsclicks = "HPENewsClicks";
var $dbtnewsclicksref = "HPENewsClicksRef";
var $dbtnewsitems = "HPENewsItems";
var $dbtnewsindex = "HPENewsIndex";
var $dbtnewscats = "HPENewsCats";
var $dbtnewsupdates = "HPENewsUpdates";
var $dbtnewsupdateseq = "HPENewsUpdateSeq";
var $dbtnewsupdatecatseq = "HPENewsUpdateCatSeq";
var $dbtnewsaccess = "HPENewsAccess";
var $dbtnewspublisher = "HPENewsPublishers";
var $dbtnewspoll = "HPENewsPollData";
var $dbtnewssearch = "HPENewsSearch";
var $dbtnewsprospects = "HPENewsProspects";
var $dbtusers = "HPEUsers";
var $dbtwebmasters = "HPEUserWebmasters";
var $dbtuseraccess = "HPEUserAccess";
var $dbtwebmastersaccess = "HPEUserAccessWebmasters";
var $dbtusersession = "HPEUserSession";
var $dbtmailpagejobs = "HPEMailPageJobs";
var $dbtusersexport = "HPEUsersExport";
var $dbtnewsagents = "HPENewsAgents";
var $dbtnewsalerts = "HPENewsAlerts";
var $dbtwatchdog = "HPEWatchDog";
function HPEDBAccess()
{
global $HPEtheConfig;
global $HPEtheThemeMaker;
$this->dbconfurl = $HPEtheConfig->dbconfurl;
$this->db_handle = DB::connect($this->dbconfurl);
if (DB::isError($this->db_handle))
{
if(!isset($GLOBALS["HPENOSHUTDOWN"]))
{
$data = array(
"message" => $HPEtheConfig->shutdownmsg
);
echo $HPEtheThemeMaker->TPLRun("shutdown", $data);
HPEWatchDog("dberror", $this->db_handle->getMessage());
$this->dberr = $this->db_handle->getMessage();
}
return;
}
$this->db_handle->setFetchMode(DB_FETCHMODE_ASSOC);
$this->dberr = "";
$this->dbtnewssites = $HPEtheConfig->dbnprefix . $this->dbtnewssites;
$this->dbtnewsbundles = $HPEtheConfig->dbnprefix . $this->dbtnewsbundles;
$this->dbtnewsclicks = $HPEtheConfig->dbnprefix . $this->dbtnewsclicks;
$this->dbtnewsclicksref = $HPEtheConfig->dbnprefix . $this->dbtnewsclicksref;
$this->dbtnewsitems = $HPEtheConfig->dbnprefix . $this->dbtnewsitems;
$this->dbtnewsindex = $HPEtheConfig->dbnprefix . $this->dbtnewsindex;
$this->dbtnewscats = $HPEtheConfig->dbnprefix . $this->dbtnewscats;
$this->dbtnewsupdates = $HPEtheConfig->dbnprefix . $this->dbtnewsupdates;
$this->dbtnewsupdateseq = $HPEtheConfig->dbnprefix . $this->dbtnewsupdateseq;
$this->dbtnewsupdatecatseq = $HPEtheConfig->dbnprefix . $this->dbtnewsupdatecatseq;
$this->dbtnewsaccess = $HPEtheConfig->dbnprefix . $this->dbtnewsaccess;
$this->dbtnewspublisher = $HPEtheConfig->dbnprefix . $this->dbtnewspublisher;
$this->dbtnewspoll = $HPEtheConfig->dbnprefix . $this->dbtnewspoll;
$this->dbtnewssearch = $HPEtheConfig->dbnprefix . $this->dbtnewssearch;
$this->dbtnewsprospects = $HPEtheConfig->dbnprefix . $this->dbtnewsprospects;
$this->dbtusers = $HPEtheConfig->dbuprefix . $this->dbtusers;
$this->dbtwebmasters = $HPEtheConfig->dbuprefix . $this->dbtwebmasters;
$this->dbtuseraccess = $HPEtheConfig->dbuprefix . $this->dbtuseraccess;
$this->dbtwebmastersaccess = $HPEtheConfig->dbuprefix . $this->dbtwebmastersaccess;
$this->dbtusersession = $HPEtheConfig->dbuprefix . $this->dbtusersession;
$this->dbtmailpagejobs = $HPEtheConfig->dbuprefix . $this->dbtmailpagejobs;
$this->dbtusersexport = $HPEtheConfig->dbuprefix . $this->dbtusersexport;
$this->dbtnewsagents = $HPEtheConfig->dbuprefix . $this->dbtnewsagents;
$this->dbtnewsalerts = $HPEtheConfig->dbuprefix . $this->dbtnewsalerts;
return;
}
function close()
{
$this->dberr = "";
return $this->db_handle->disconnect();
}
function query($query)
{
$this->dberr = "";
$query = ereg_replace(";\$", "", $query);
$result = $this->db_handle->query($query);
if(DB::isError($result))
{
$this->dberr = $result->getMessage() . ": " . $query;
HPEWatchDog("dberror", $this->dberr);
}
return $result;
}
function iserror($result)
{
return (DB::isError($result) ? 1 : 0);
}
function getrowcount($result)
{
$this->dberr = "";
if (DB::isError($result))
return 0;
else
return $result->numRows($result);
}
function getaffectedrowcount()
{
$this->dberr = "";
return $this->db_handle->affectedRows();
}
function getrow($result)
{
$this->dberr = "";
if ($result)
return $result->fetchRow(DB_FETCHMODE_ASSOC);
else
return false;
}
function one_data($query)
{
$this->dberr = "";
$one = $this->query($query);
if(DB::isError($one))
return 0;
$row = $one->fetchRow(DB_FETCHMODE_ORDERED);
return $row[0];
}
function one_array($query)
{
$this->dberr = "";
$one = $this->query($query);
if(DB::isError($one))
return false;
return $one->fetchRow(DB_FETCHMODE_ASSOC);
}
function next_id($sequence)
{
$this->dberr = "";
return $this->db_handle->nextId($sequence);
}
function insert($table, $params, $values, $spec = "")
{
$n = count($params);
if($n != count($values))
die("size of param and value arrays don't match");
$query = "INSERT $spec INTO $table (";
for($i=0; $i<$n; $i++)
{
$query .= $params[$i];
if($i != $n-1)
$query .= ",";
}
$query .= ") VALUES (";
for($i=0; $i<$n; $i++)
{
$query .= $values[$i];
if($i != $n-1)
$query .= ",";
}
$query .= ")";
// echo "<pre>" . htmlentities($query) . "</pre>\n";
return $this->query($query);
}
function replace($table, $params, $values, $spec = "")
{
$n = count($params);
if($n != count($values))
die("size of param and value arrays don't match");
$query = "REPLACE $spec INTO $table (";
for($i=0; $i<$n; $i++)
{
$query .= $params[$i];
if($i != $n-1)
$query .= ",";
}
$query .= ") VALUES (";
for($i=0; $i<$n; $i++)
{
$query .= $values[$i];
if($i != $n-1)
$query .= ",";
}
$query .= ")";
// echo "<pre>" . htmlentities($query) . "</pre>\n";
return $this->query($query);
}
function update($table, $where, $params, $values, $spec = "")
{
$n = count($params);
if($n != count($values))
die("size of param and value arrays don't match");
$query = "UPDATE $spec $table SET ";
for($i=0; $i<$n; $i++)
{
$query .= $params[$i] . "=" . $values[$i];
if($i != $n-1)
$query .= ", ";
}
$query .= " WHERE $where";
// echo "<pre>" . htmlentities($query) . "</pre>\n";
return $this->query($query);
}
function escapeString($str)
{
return $this->db_handle->quote($str);
}
};
?>