executing 2 query with one connection

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

executing 2 query with one connection

Post by CurlyDev »

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.
Eric!
DevNet Resident
Posts: 1146
Joined: Sun Jun 14, 2009 3:13 pm

Re: executing 2 query with one connection

Post by Eric! »

If you post a bunch of code, please put it in between code tags.
[syntax=php]YOUR CODE[/syntax]
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: executing 2 query with one connection

Post by jackpf »

I don't even see a query.
Post Reply