<?php
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// bGlobalSourcing [Programmer: Md. Aminul Islam] //
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// Class: ClsDatabaseOperation: Used for Add,Retrieve Data from a Table of Database //
// [ Limitation: ] //
// [ Required Folder: None] //
//==============================================================================================================================//
//function SaveDataIntoTable($DatabaseTableName,$TableFields,$CheckDuplicateCondition,$ConditionalErrorMsg,$SuccessMessage,$ErrorMessage):- //
//------------------------------------------------------------------------------------------------------------------------------//
// This Function Takes 6 Parameters:- //
// $DatabaseTableName = The Table Name Into which want to insert data //
// $TableFields = One Dimensional Array which contain all the fields of current table //
// $CheckDuplicateCondition = Query for checking this value exists or not. //
// $ConditionalErrorMsg = If Duplicate Value found This Message will Return. //
// $SuccessMessage = If Data Insert Successfully into Table //
// $ErrorMessage = If Error Occured while insertion data into Table //
// This Function Return:- //
// "The Table Does Not Exists." If the table doesn't exists. //
// " $SuccessMessage " If the data inserted into table successfully //
// " $ErrorMessage " If the data can't inserted into table successfully //
/*
Example:-
$ObjForumData=new ClsDatabaseOperation();
$DatabaseTableName="forum_info";
$TableFieldValues=array("''","'$txtForumName'","'$CurrentDate'","$CurrentUserId","'$txtForumType'","'$txtForumPassword'");
[ First '' is for Auto Increment.]
$CheckDuplicateCondition = "ForumName='$txtForumName' and ParentForumId=0";
$ConditionalErrorMsg = "The Forum is Already Exists.";
$SuccessMessage = "Forum Added Successfully.";
$ErrorMessage = "Error while adding forum.";
$Message = $ObjForumData->SaveDataIntoTable($DatabaseTableName,$TableFieldValues);
*/
//==============================================================================================================================//
// function RetrieveDataFromTable($DatabaseTableName,$MessageForEmptyTable="The Table is Empty.",$Condition="",$OrderByCol=""):-//
//------------------------------------------------------------------------------------------------------------------------------//
// This Function Takes 4 Parameter:- //
// $DatabaseTableName = The Table Name from which you want to retrieve data //
// $MessageForEmptyTable = The Message returned If the Table is Empty //
// $Condition = Condition For Select Data from Database. //
// $OrderByCol = Orderby clause (if necessary). //
// This Function Return:- //
// "The Table Does Not Exists." If the table doesn't exists. //
// "The Table Is Empty." If the table exists but have no data. //
// "$TableData" Return Tables All Data In Two Dimensional Array. //
//------------------------------------------------------------------------------------------------------------------------------//
/*
Example:-
$DatabaseTableName="student";
$MessageForEmptyTable="Currently No Students Information is Available."
$FullTableData=$ObjStudentData->RetrieveDataFromTable($DatabaseTableName,$MessageForEmptyTable);
echo "<br><H3>Finally Operation Result(For RetrieveDataFromTable() Function <br>:</H3>";
if(is_array($FullTableData))
{
echo "<table border='1'>";
foreach($FullTableData as $SingleRowData)
{
echo "<tr>";
foreach($SingleRowData as $SingleCellData)
echo "<td align='center'>$SingleCellData</td>";
echo "</tr>";
}
echo "</table>";
}
else
echo "<H4>$FullTableData</h4>";
*/
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
require_once ("ClsConnection.cls.php");
class ClsDatabaseOperation extends ClsConnection
{
function ClsDatabaseOperation()
{
$this->ClsConnection(); //Connection Class Constructor for Database Connection.
//echo "TableUpdate Class Constructor";
}
function SaveDataIntoTable($DatabaseTableName,$TableFields,$SuccessMessage="Data saved into database successfully.",
$ErrorMessage="Error while adding data into database.",$CheckDuplicateCondition="",$ConditionalErrorMsg="")
{
//Check For Table Existance
if($this->DataBaseTableExists($DatabaseTableName)=="False")
return "The Table Does Not Exists.";
//Check Condition For Insert ($CheckDuplicateCondition)
if($CheckDuplicateCondition!="")
{
$QueryForCheckDuplicate="select * from $DatabaseTableName where $CheckDuplicateCondition";
if(mysql_num_rows(mysql_query($QueryForCheckDuplicate))==0)
$InsertPermission="True"; //No Duplicate Value Found.
else
$InsertPermission="False";
}
else
$InsertPermission="True";
if($InsertPermission=="True")
{
$GenerateQuery="insert into $DatabaseTableName values(";
foreach($TableFields as $SingleField)
$GenerateQuery.=$SingleField.",";
$GenerateQuery=substr($GenerateQuery,0,strlen($GenerateQuery)-1).")";
//echo $GenerateQuery;
if(mysql_query($GenerateQuery))
return $SuccessMessage;
else
return $ErrorMessage;
}
else
return $ConditionalErrorMsg; //Error Because Same Value already exists in $DatabaseTableName table
}
function RetrieveDataFromTable($DatabaseTableName,$MessageForEmptyTable="The Table is Empty.",$Condition="",$OrderByCol="")
{
//If the Table($DatabaseTableName) does not exists.
if(mysql_num_rows(mysql_query("SHOW TABLES LIKE '".$DatabaseTableName."'"))<1)
return "The Table Does Not Exists.";
//Retrieve all data from Table.
$BuildSelQuery=$this->QueryBuilderWithCondition($DatabaseTableName,$Condition,$OrderByCol);
$QueryTableData=mysql_query($BuildSelQuery)or die("Can't Execute Database Query Right Now.");
if(mysql_num_rows($QueryTableData)>0)
{
//$FindNumberOfColumn= Total column of current table($DatabaseTableName) which will be used as index.
$QueryForCountCol=mysql_fetch_row(mysql_query($BuildSelQuery));
for($i=0;$i<=100;$i++)
if(isset($QueryForCountCol[$i]))
continue;
else
break;
$FindNumberOfColumn=$i;
//echo "Total col=$FindNumberOfColumn";
//Start Process: $TableData=All data of $DatabaseTableName
$QueryTableData=mysql_query($BuildSelQuery);
$Row=0;
while($RsTableData=mysql_fetch_row($QueryTableData))
{
for($Col=0;$Col<$FindNumberOfColumn;$Col++) //Col= Indicating Column No & Counter
$TableData[$Row][$Col]=$RsTableData[$Col];
$Row++;
}
//End Process: $TableData=All data of $DatabaseTableName
return $TableData; //Return Tables All Data In Two Dimensional Array Format.
}
else
return $MessageForEmptyTable;
}
}
?>
|