Location: PHPKode > scripts > Expandable Menu > expandable-menu/db_connect.php
<?php
class DbConnect {
	var $_DbHost;
	var $_DbName;
	var $_DbTableName;
	var $_DbUserName;
	var $_DbUserPass;
	var $Results	= array();
	function DbSetVars($H,$N,$Un,$Up)
	{
		if ($H == "" || $N == "" || $Un == "" || $Up == "") {
			return false;
		} else {
			$this->_DbHost			= $H;
			$this->_DbName			= $N;
			$this->_DbUserName		= $Un;
			$this->_DbUserPass		= $Up;
			return true;
		}
	}
	function GetDbTableName()
	{
		return $this->_DbTableName;
	}
	function SetDbTableName($x)
	{
		$this->_DbTableName			= $x;
	}
	function RunQuery($Q)
	{
		mysql_connect($this->_DbHost, $this->_DbUserName, $this->_DbUserPass);
		mysql_select_db($this->_DbName);
		$result = mysql_query($Q) or die("MySQL Query Error: <br>$Q<br>". mysql_error());
		return $result;
	}
	function GetResults($ExInf='')
	{
		$query = "SELECT * FROM `". $this->_DbTableName ."`". $ExInf;
		$result = $this->RunQuery($query);
		if (mysql_num_rows($result) == 0) {
			return false;
		} else {
			$tArr = array();
			while ($row = mysql_fetch_object($result)) {
				foreach($row as $r) {
					array_push($tArr, $r);
				}
				$tArr = array_values($tArr);
				$tArr[] = $this->_DbTableName;
				array_push($this->Results, $tArr);
				foreach ($tArr as $i => $value) {
				    unset($tArr[$i]);
				}
			}
			mysql_free_result($result);
			return true;
		}
	}
	function GetResult($id,$tbl)
	{
		$query = "SELECT * FROM $tbl WHERE ProductID='$id' LIMIT 1";
		$result = $this->RunQuery($query);
		if (mysql_num_rows($result) == 0) {
			return false;
		} else {
			$tArr = array();
			while ($row = mysql_fetch_object($result)) {
				foreach($row as $r) {
					array_push($tArr, $r);
				}
				$tArr = array_values($tArr);
				$tArr[] = $tbl;
			}
			mysql_free_result($result);
			return $tArr;
		}
	}
}
?>
Return current item: Expandable Menu