PHP Classes

File: ConnectionClass

Recommend this page to a friend!
  Classes of Md. Aminul Islam   Insert Retrieve data from Table   ConnectionClass   Download  
File: ConnectionClass
Role: Class source
Content type: text/plain
Description: Used as DB Connector and Sql Query Generator
Class: Insert Retrieve data from Table
Query a database to insert and retrieve table rows
Author: By
Last change: Upgrade of Connection Class. Excellent Features are included Specially SQL Query Generator and Two way of Database Connection for any Project(Fully User Defined).
Date: 18 years ago
Size: 3,740 bytes
 

Contents

Class file image Download
<?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;
        }
    }
?>