opeing a secon db2/400 connection

General discussion on Zend Server for IBM System i
Post Reply
lkleinman
Posts: 9
Joined: Wed Jan 26, 2011 8:00 pm

opeing a secon db2/400 connection

Post by lkleinman » Tue Aug 02, 2016 2:16 am

HI all -

I am trying to run a PHP script using Zend Server for IBM i in which I first connect to the IBM i database using a "default" user and password, then do a few things that determine who the actual user is, and then connect using that user's user profile and password. I used to do this using the old "i5_connect" method, but am switching to the ToolkitService::getInstance method.

Heres the code I'm using

require_once('ToolkitService.php');
$db = 'S1006F9T';
$user = 'WEB@#USER';
$password = 'xxxx';

// Set up connection to use for running programs

try {
$connection = ToolkitService::getInstance($db, $user, $password);
}

catch (Exception $e)
{
echo $e->getMessage(), "\n";
exit();
}

// set stateless mode for easy testing (no 'InternalKey' needed).
$connection->setOptions(array('stateless'=>true));




This works fine. Afterwards, I have some code that figures out based on user input to a form what the real user and password should be, and i INCLUDE a script that then contains the following


require_once('ToolkitService.php');

$db = 'S1006F9T';

$user = $_SESSION["User"];
$password = $_SESSION["Password"];


try {
$connection = ToolkitService::getInstance($db, $user, $password);
}

catch (Exception $e)
{echo 'xxx catch section of loginlitweb';
echo $e->getMessage(), "\n";
exit();
}


if (!$connection) { echo "xxx here";
if ($FromSignOn)
$Result = 'Fail';
Else
die ("Could not connect to database " );
}




This does not seem to do anything. Regardless of whether the values in $user and in $password are valid , the catch section of the code never seems to execute. I expected that using a bad user/passowrd would trigger the catch. It looks as if the original connection with my default user/password remians active no matter what. This method used to work with -5_connect.

Any ideas what I'm doing wrong?.

Post Reply