<?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="";
var $DBName="class_test";
//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 Query with A Specified Condition.
function QueryBuilderWithCondition($TableName,$Condition="",$OrderByCol="")
{
if($Condition=="")
$Query="select * from $TableName";
else
$Query="select * from $TableName where $Condition";
if($OrderByCol!="")
$Query.=" ORDER BY $OrderByCol";
return $Query;
}
}
?>
|