Jump to content

[SOLVED] Creating 2 instance of class and accessing next result set


Curlyfreak

Recommended Posts

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.

Link to comment
Share on other sites

I have a DataAccessLayer.class.php, BusinessLayer.class.php

 

When you develop your application to be seperated amongst different layers/tiers to be independently developed of each other doesn't mean you will have a class named after the tier/layer. The same misconception exists amongst the MVC pattern where people believe you have 3 classes: Controller, View and Model while each usually contains multiple classes in each tier.

 

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.

 

is because of

 

include 'DataAccessLayer.class.php';

 

use include_once()

 

2. When I tried to add the customException.class.php to my BusinessLayer.class.php it breaks down.

 

because you didn't include it:

 

//include 'CustomException.class.php';  // when I include this file it gives error

 

3. Not able to access my next result after function call

 

solve the previous 2 and this should work.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.