Creating 2 instance and accessing result set

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
CurlyDev
Forum Newbie
Posts: 3
Joined: Sat Sep 05, 2009 9:52 am

Creating 2 instance and accessing result set

Post by CurlyDev »

Hi Guys,

I am stuck with something, may be very simple for you guys to solve. May be some basics PHP 5.

I have a DataAccessLayer.class.php, BusinessLayer.class.php, Config.class.php, customException.class.php and Testing1.php(which is my UI).


Query:
1. When I tried to 2 instance of my BusinessLayer in my Testing.php first instance gets created without any problem, but not able to create the 2 instance.
2. When I tried to add the customException.class.php to my BusinessLayer.class.php it breaks down.
3. Not able to access my next result after function call

below is my code.

-----------------------------------------------------------------------------------------------------

class DataAccessLayer

{
private $connect_mysqli;

public function __construct()
{
include 'CustomException.class.php';
$this->DatabaseConnectionObject();
}

/* DatabaseConnectionObject creates database connection objects */
private function DatabaseConnectionObject()
{
try
{

include 'Config.class.php';
$this->connect_mysqli = new mysqli($Config_HostName,$Config_UserName,$Config_Password,$Config_Database);

if (mysqli_connect_errno())
{
printf("Connect failed: %s\n", mysqli_connect_error());
}
else
{
printf("Connect successful");
}
}
catch(customException $ex)
{
$ex->ProcessErrorMessage();
}
}

/* ExecuteSP is for obtaining data by passing stored procedure names */
public function ExecuteSP($StoredProcedureName)
{
try
{
return $this->connect_mysqli->query("CALL ".$StoredProcedureName."()");
}
catch(customException $ex)
{
$ex->ProcessErrorMessage();
}
}
}

-----------------------------------------------------------------------------------------------------

class customException extends Exception
{
public function ProcessErrorMessage()
{
include 'FileOperations.class.php';
$errorMsg = " \r\n ".'Error on file : '.$this->getFile()." \r\n ".'Error on line : '.$this->getLine()." \r\n ".'Error Message : '.$this->getMessage()." \r\n ".'Error date : '.time()." \r\n ";

$FileOperation = new FileOperations();
$this->$FileOperation->WriteErrorLog($errorMsg);
}
}

-----------------------------------------------------------------------------------------------------

class BusinessLayer
{
private $objDataAccessLayer;

public function __construct()
{
//include 'CustomException.class.php'; // when I include this file it gives error
$this->Initalize();

}

private function Initalize()
{
include 'DataAccessLayer.class.php';
$this->objDataAccessLayer = new DataAccessLayer();
}

public function GetCityByState($ParamArray)
{
try
{
return $this->objDataAccessLayer->ExecuteSPwithParameters('SP Name',$ParamArray);
}
catch(customException $ex)
{
$ex->ProcessErrorMessage();
}
}

public function GetCountry()
{
try
{
return $this->objDataAccessLayer->ExecuteSP('SP name');
}
catch(customException $ex)
{
$ex->ProcessErrorMessage();
}
}
}

-----------------------------------------------------------------------------------------------------

Testing1.php

include 'BusinessLayer.class.php';
$newtest = new BusinessLayer();

$resultset = $newtest->GetCityByState($testarray);

// process the $resultset


$resultset1 = $newtest->GetCountry();
print 'query 2 - 1'; // It works fine perfectly up till here. (May be it's not providing the next result set to process - that's my guess).

// process the $resultset

-----------------------------------------------------------------------------------------------------

Please let me know what am I doing wrong.

Thanks in advance.
Post Reply