Location: PHPKode > scripts > Tiny P2P > tiny-p2p/ClsConnection.cls.php
<?php
	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
	//									bGlobalSourcing																				//
	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
	//		This Page Establish connection with MySql(Database). + QueryBuilder function is for build query.						//
	//==============================================================================================================================//
	//	function ClsConnection():- 																									//
	//------------------------------------------------------------------------------------------------------------------------------//
	//	Just Change These Variables As you need	:-																					//
	//	$Host="HostName"		eg. $Host="www.bglobalsourcing.com"																	//
	//	$UserNam="UserName"		eg. $UserNam="bglobal"																				//
	//	$Paswrd="Password"		eg. $Paswrd="*******"																				//
	//	$DbName="DatabaseName"	eg. $DBName="bGlobal"																				//
	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
	//==============================================================================================================================//
	//	function QueryBuilderWithCondition($TableName,$Condition,$OrderByCol):- 																//
	//------------------------------------------------------------------------------------------------------------------------------//
	//	" $TableName "		The Name of Database Table.(Select * from $TableName)													//
	//	" $Condition "		The Condition Appended End of Query (where Filed1="something" [and Field2>40])							//
	//	" $OrderByCol "		The Order By Clause (ORDER BY Filed1[DESC])																//
	//==============================================================================================================================//
	class ClsConnection
	{
		/*
		var $Host="localhost";
		var $UsrNam="root";
		var $Paswrd="pl4tinum";
		var $DBName="theplatinumlist_com_-_platinum";
		*/
		//
		var $Host="localhost";
		var $UsrNam="root";
		var $Paswrd="";
		var $DBName="platinul1";
		//

		//Establish Database Connection While Creating or Inherit this class.
		function ClsConnection()
		{
			mysql_connect($this->Host,$this->UsrNam,$this->Paswrd)or die("Error in localhost connection.");
			mysql_select_db($this->DBName)or die("Error in Database Connections");
			//echo "Connection Established (Connection Class)";
		}

		function UserDefineConnection($HostName,$UserName,$Password,$DatabaseName)
		{
			if($HostName!="")
				$this->Host=$HostName;
			if($UserName!="")
				$this->UsrNam=$UserName;
			if($Password!="")
				$this->Paswrd=$Password;
			if($DatabaseName!="")
				$this->DBName=$DatabaseName;

			mysql_connect($this->Host,$this->UsrNam,$this->Paswrd)or die("Error in localhost connection.");
			mysql_select_db($this->DBName)or die("Error in Database Connections");
			//echo "Connection Established by user defined Data.(Connection Class)";
		}
		
		//Check Table $DatabaseTableName Existance. If Exists return True otherwise False.
		function DataBaseTableExists($DatabaseTableName)
		{
			if(mysql_num_rows(mysql_query("SHOW TABLES LIKE '".$DatabaseTableName."'"))==1)
				return "True";	//Exists
			else
				return "False";	//Not Exists
		}
		
		//This Function Build " SQL SELECT " Query with A Specified Condition.
		function BuildSelectQuery($TableName,$Condition="",$OrderByCol="",$OrderAscOrDesc="asc")
		{
			if($Condition=="")
				$Query="select * from $TableName";
			else
				$Query="select * from $TableName where $Condition";
			if($OrderByCol!="")
			{
				$Query.=" ORDER BY $OrderByCol";
				if($OrderAscOrDesc!="asc" && $OrderAscOrDesc!="")
					$Query.=" ".$OrderAscOrDesc;
			}
			return $Query;
		}
	
		//This Function Build " SQL UPDATE " Query with A Specified Condition.
		function BuildUpdateQuery($DatabaseTableName,$UpdateFieldsAndValues,$UpdateCondition="")
		{
			$UpdateQuery="UPDATE $DatabaseTableName SET ";
			foreach($UpdateFieldsAndValues as $ColName=>$UpdateVal)
			{
				$UpdateVal=$this->RemoveUnexpectedBR($UpdateVal);
				$UpdateVal=$this->AddSlash($UpdateVal);
				$UpdateQuery.="$ColName = $UpdateVal, ";
			}
			$UpdateQuery=substr($UpdateQuery,0,strlen($UpdateQuery)-2);
			if($UpdateCondition!="")
				$UpdateQuery.=" where $UpdateCondition";
			return $UpdateQuery;
		}
		
		function BuildDeleteQuery($TableName,$Condition="")
		{
			$Query="delete from $TableName";
			if($Condition!="")
				$Query.="where $Condition";
			return $Query;
		}
		
		function CheckDuplicateValExist($SelQuery)
		{
			//echo $SelQuery;
			$TmpQ=mysql_query($SelQuery) or die("Cant execute query for check duplicate value existance.");
			if(mysql_num_rows(mysql_query($SelQuery))==0)
				return false;
			else
				return true;
		}
		
		function SearchImageAndDelete($DatabaseTblName,$TblColNameForCondition,$TblColValForCondition,$TblColNameForImgFile,$ImgFolderLoc)
		{
			$SelQueryForDelImg=mysql_query("select $TblColNameForImgFile from $DatabaseTblName where $TblColNameForCondition=$TblColValForCondition")or die("Database Error Inside SearchImageAndDelete Function");
			$DataOfImg=mysql_fetch_row($SelQueryForDelImg);
			$ImgBaseName=$DataOfImg[0];
			$ImgWithPath=$ImgFolderLoc."/".$ImgBaseName;
			if(file_exists($ImgWithPath))
				unlink($ImgWithPath);
			else
				echo "File Not Found For Delete.";
		}

		function AddSlash($SingleField)
		{
			$SingleField=trim($SingleField);
			if(substr($SingleField,0,1)=="'" && strlen($SingleField)>2 && (!strrpos($SingleField,"\\")) )
			{
				//echo "<br>Original: ".$SingleField;
				$SingleField=substr($SingleField,1,strlen($SingleField)-2);
				//echo "<br>Reduce ' sign: ".$SingleField;
				$SingleField="'".addslashes($SingleField)."'";
				//echo "<br>After add slash: ".$SingleField;
			}
			else
			if(strlen($SingleField)>2 && (!strrpos($SingleField,"\\")))
				$SingleField=addslashes($SingleField);
			return $SingleField;
		}
		function RemoveUnexpectedBR($UpdateVal)
		{
			if(substr($UpdateVal,0,6)=="<br />")	//Remove Beginnig BR.
				$UpdateVal=substr($UpdateVal,6);
			$UpdateVal=str_replace("<br /><br />","<br>",$UpdateVal);
			return $UpdateVal;
		}
	}
?>
Return current item: Tiny P2P