Connecting Tech Pros Worldwide Help | Site Map

DB2 PHP connection issue

Newbie
 
Join Date: Oct 2007
Posts: 14
#1: Nov 13 '08
I am trying to connect to our DB2 DB with PHP using ADOdb. Below is my environment.

Windows XP
PHP 5.2.5
DB2 Run-Time Client 8.2
IIS

I connect with the following code:
[PHP]
include('adodb/adodb.inc.php');
$db = ADONewConnection('db2');

$dsn = "driver={IBM db2 odbc DRIVER};Database=$DBName;hostname=$Host;port=$Port ;protocol=TCPIP;uid=$User;pwd=$Password";
if ($db->Connect($dsn)) {
echo "It worked";
} else {
echo "***didn't work db->Connect(dsn)<br>";
echo 'SQLSTATE: '.$db->ErrorNo()."<br>";
echo 'Message: '.$db->ErrorMsg()."<br><br>";
}
[/PHP]

I get the following error:
Expand|Select|Wrap|Line Numbers
  1. ***didn't work db->Connect(dsn)
  2. SQLSTATE: 42968
  3. Message: [IBM][CLI Driver] SQL8002N Connect processing failed; a valid product license was not found. SQLSTATE=42968 SQLCODE=-8002
  4.  
I know I am using the correct iSeries port, the correct DB name, and a fully licensed server. Has anyone ever seen this error?
Lives Here
 
Join Date: Sep 2006
Posts: 12,070
#2: Nov 14 '08

re: DB2 PHP connection issue


Are you able to connect to the database from the command line?
If you installed your license key correctly then you might need to contact your IBM representative.
Newbie
 
Join Date: Oct 2007
Posts: 14
#3: Nov 14 '08

re: DB2 PHP connection issue


I GOT IT!

You need to install iSeries Client Access on your PHP server to get the correct drivers you need. I did a custom install and selected to install the Required Programs and Data Access including Data Transfer, ODBC, and OLE DB Provider.

Then I connected as below.
[PHP]
include('adodb/adodb.inc.php');
$db = ADONewConnection('odbc');
$dsn = "DRIVER={iSeries Access ODBC Driver};SYSTEM=$Host;DATABASE=$DBName;PROTOCOL=TCP IP;PORT=$Port;";
if ($db->Connect($dsn,$User,$Password)){
echo "It worked";
$sql = "SELECT table_name, table_type, table_schema, system_table_name FROM qsys2.systables";
$rs = $db->Execute($sql);
if (!$rs) echo "<p>no records</p>";
else {
$result = $rs->GetArray();
echo "<pre>";
print_r($result);
echo "</pre>";
}
} else {
echo "Not working";
echo 'SQLSTATE: '.$db->ErrorNo()."<br>";
echo 'Message: '.$db->ErrorMsg()."<br><br>";
}
[/PHP]
Reply