executing 2 query with one connection
Posted: Sun Sep 20, 2009 11:41 am
Hi Guys,
Hopefully my last question I am trying to call 2 mysql queries using single connection, but I am not able to get the result set of my second query. Wondering
can you guys can help me in this. I am trying to access it under Testing1.php file. Please see the code below.
DataBaseAccessLayer.php
-----------------------
class DataAccessLayer
{
private $connect_mysqli;
public function __construct()
{
include_once 'CustomException.class.php';
$this->DatabaseConnectionObject();
}
private function DatabaseConnectionObject()
{
print 'this is databaseconnect';
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();
}
}
public function ExecuteSP($StoredProcedureName)
{
try
{
return $this->connect_mysqli->query("CALL ".$StoredProcedureName."()");
}
catch(customException $ex)
{
$ex->ProcessErrorMessage();
}
}
public function ExecuteSPwithParameters($StoredProcedureName,$ParamArray)
{
try
{
return $this->connect_mysqli->query("CALL ".$StoredProcedureName."(".$this->BuildParameters($ParamArray).")");
}
catch(customException $ex)
{
$ex->ProcessErrorMessage();
}
}
}
---------------------------------------------------------------------------------------------------------------
BusinessLayer.class.php
-----------------------
class BusinessLayer
{
private $objDataAccessLayer;
public function __construct()
{
//include 'CustomException.class.php';
print 'testing BL';
$this->Initalize();
}
private function Initalize()
{
include_once 'DataAccessLayer.class.php';
print 'Layer BL DAL';
$this->objDataAccessLayer = new DataAccessLayer();
}
public function GetCityByState($ParamArray)
{
try
{
return $this->objDataAccessLayer->ExecuteSPwithParameters('SP',$ParamArray);
}
catch(customException $ex)
{
$ex->ProcessErrorMessage();
}
}
public function GetCountry()
{
try
{
return $this->objDataAccessLayer->ExecuteSP('SP');
}
catch(customException $ex)
{
$ex->ProcessErrorMessage();
}
}
}
---------------------------------------------------------------------------------------------------------------
Testing1.php
------------
include 'BusinessLayer.class.php';
$newtest = new BusinessLayer();
$testarray =
array( 0=>array('dt'=>'str','v'=>'KAR'));
$resultset = $newtest->GetCityByState($testarray);
// I am able to access the recoed set here.
$resultset1 = $newtest->GetCountry();
// But I am not able to get any records here - wondering should I use some function to move to next record set
Thanks in advance.
Hopefully my last question I am trying to call 2 mysql queries using single connection, but I am not able to get the result set of my second query. Wondering
can you guys can help me in this. I am trying to access it under Testing1.php file. Please see the code below.
DataBaseAccessLayer.php
-----------------------
class DataAccessLayer
{
private $connect_mysqli;
public function __construct()
{
include_once 'CustomException.class.php';
$this->DatabaseConnectionObject();
}
private function DatabaseConnectionObject()
{
print 'this is databaseconnect';
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();
}
}
public function ExecuteSP($StoredProcedureName)
{
try
{
return $this->connect_mysqli->query("CALL ".$StoredProcedureName."()");
}
catch(customException $ex)
{
$ex->ProcessErrorMessage();
}
}
public function ExecuteSPwithParameters($StoredProcedureName,$ParamArray)
{
try
{
return $this->connect_mysqli->query("CALL ".$StoredProcedureName."(".$this->BuildParameters($ParamArray).")");
}
catch(customException $ex)
{
$ex->ProcessErrorMessage();
}
}
}
---------------------------------------------------------------------------------------------------------------
BusinessLayer.class.php
-----------------------
class BusinessLayer
{
private $objDataAccessLayer;
public function __construct()
{
//include 'CustomException.class.php';
print 'testing BL';
$this->Initalize();
}
private function Initalize()
{
include_once 'DataAccessLayer.class.php';
print 'Layer BL DAL';
$this->objDataAccessLayer = new DataAccessLayer();
}
public function GetCityByState($ParamArray)
{
try
{
return $this->objDataAccessLayer->ExecuteSPwithParameters('SP',$ParamArray);
}
catch(customException $ex)
{
$ex->ProcessErrorMessage();
}
}
public function GetCountry()
{
try
{
return $this->objDataAccessLayer->ExecuteSP('SP');
}
catch(customException $ex)
{
$ex->ProcessErrorMessage();
}
}
}
---------------------------------------------------------------------------------------------------------------
Testing1.php
------------
include 'BusinessLayer.class.php';
$newtest = new BusinessLayer();
$testarray =
array( 0=>array('dt'=>'str','v'=>'KAR'));
$resultset = $newtest->GetCityByState($testarray);
// I am able to access the recoed set here.
$resultset1 = $newtest->GetCountry();
// But I am not able to get any records here - wondering should I use some function to move to next record set
Thanks in advance.