A
download database.mysql.inc
Language: NonCode
LOC: 0
Project Info
HPE
Server: SourceForge
Type: cvs
...ceForge\h\hpe\hpe\hpe1\HPE\
   .cvsignore
   clickerr.inc
   config.inc
   Config_File.class.php
   database.inc
   database.mysql.inc
   database.pear.inc
   FormChek.js
   HPE.inc
   HPEbase.inc
   HPEUsers.default.xml
   HPEUsers.guest.xml
   layout.js
   local.inc
   modules.inc
   ...andlers.addChannel.ftsc
   navcond.js
   newsaccess.inc
   newssource.inc
   newstools.js
   overlib.js
   overlib_mini.js
   pagemaker.inc
   pages.inc
   PHPClientSniffer.inc
   phpodp.inc
   publisher.inc
   services.inc
   sitelister.inc
   Smarty.addons.php
   Smarty.class.php
   Smarty_Compiler.class.php
   sourcetools.js
   thememaker.inc
   toparser.inc
   user.edit.inc
   user.inc
   xmlrpc.inc
   xmlrpcs.inc
   xmltree.inc

<?
/*

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

*/


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;

		if(preg_match("%(.+)://(.+):(.*)@(.+)/(.+)%", $this->dbconfurl, $matches))
		{
			$protocole = $matches[1];
			$login = $matches[2];
			$passwd = $matches[3];
			$host = $matches[4];
			$db = $matches[5];

			if($protocole != "mysql")
				die("Can't work with database type '$protocole'");
			$this->db_handle = mysql_connect($host, $login, $passwd);
			if (!$this->db_handle)
			{
				if(!isset($GLOBALS["HPENOSHUTDOWN"]))
				{
					$data = array(
								"message" => $HPEtheConfig->shutdownmsg
							);

					echo $HPEtheThemeMaker->TPLRun("shutdown", $data);
					$this->dberr = mysql_error();
					HPEWatchDog("dberror", $this->dberr);
				}
				return;
			}
			mysql_select_db($db) or die("Could not select database '$db'");
		}
		else die("Failed to match db host config");

		$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 = mysql_query($query, $this->db_handle);
		if($result)
			return $result;

		$this->dberr = mysql_error() . ": " . $query;
		HPEWatchDog("dberror", $this->dberr);
	}


	function iserror($result)
	{
		return (!$result);
	}


	function getrowcount($result)
	{
		$this->dberr = "";
		if (!$result)
			return 0;
		else
			return mysql_num_rows($result);
	}


	function getaffectedrowcount()
	{
		$this->dberr = "";
		return mysql_affected_rows($this->db_handle);
	}


	function getrow($result)
	{
		$this->dberr = "";
		if ($result)
			return mysql_fetch_array($result, MYSQL_ASSOC);
		else
			return false;
	}


	function one_data($query)
	{
		$this->dberr = "";

		$one = $this->query($query);
		if(!$one)
			return 0;

		$row = mysql_fetch_array($one, MYSQL_NUM);
		return $row[0];
	}


	function one_array($query)
	{
		$this->dberr = "";

		$one = $this->query($query);
		if(!$one)
			return false;

		return $this->getrow($one);
	}


	function next_id($sequence)
	{
		$this->dberr = "";
		$result = $this->query("UPDATE ${sequence}_seq SET id=id+1");
		if($result)
		{
			return $this->one_data("SELECT MAX(id) FROM ${sequence}_seq");
		}
		else
		{
			die(mysql_error());
		}
	}


	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)
	{
		$nstr = "'" . mysql_escape_string($str) . "'";
		return $nstr;
	}


};

?>

About Koders | Resources | Downloads | Support | Black Duck | Terms of Service | DMCA | Privacy Policy | Contact Us