Page 1 of 1

Connecting to a DB2 Database using PHP and ADOdb

Posted: Thu Aug 10, 2006 11:35 am
by jvilches
Hi,

I'm trying to connect to a DB2 database on an AS400 server on my local network, using PHP and the ADOdb library.

There is some documentation on doing this here

Here is the code to connect to DB2

Code: Select all

$db =& ADONewConnection('db2');
	$dsn = "driver={IBM db2 odbc DRIVER};Database=sample;hostname=localhost;port=50000;protocol=TCPIP;".
			"uid=root; pwd=secret";
	$db->Connect($dsn);
But when I do this I get an Error Message IM002 telling me that I have not specified the ODBC driver.

Checking the documentation, the is a prerequisite for this connection. I need to have a DB2 CLI/ODBC interface. What is this? any Ideas on where to get this missing driver I need?

I need this driver for Windows XP, and also a version for Ubuntu Linux Server 6.06 LTS.

If anyone knows where to get this I would really appreciate your help.

Thanks.

Posted: Sat Aug 12, 2006 1:13 am
by RobertGonzalez

Wich One?

Posted: Sun Aug 13, 2006 11:48 pm
by jvilches
Thanks!

But there are a lot of different downloads there, wich one do I need?

This are the options:

DB2 Administration Client
DB2 Application Development Client
DB2 Connect Enterprise Edition or
DB2 Connect Unlimited Edition or
DB2 Connect Application Server Edition or
DB2 Connect Unlimited Edition for iSeries
DB2 Connect Personal Edition
DB2 Cube Views
DB2 Data Links Manager
DB2 Enterprise Server Edition
DB2 Express Edition
DB2 Information Integrator Non-Relational Wrappers
DB2 Information Integrator Relational Wrappers
DB2 Personal Edition
DB2 Query Patroller
DB2 Run-Time Client
DB2 Spatial Extender
DB2 Warehouse Manager
DB2 Workgroup Server Edition or
DB2 Workgroup Server Unlimited Edition

All I need to do is connect to a DB2 Database on another computer with a PHP Script and using ADOdb

Posted: Mon Aug 14, 2006 12:08 am
by RobertGonzalez
I would guess either of the two clients at the beginning of the list. But that is just a guess.

Re: Connecting to a DB2 Database using PHP and ADOdb

Posted: Thu Nov 13, 2008 10:17 am
by repp9418
Did you ever get this to work?

I am attempting the exact same connection. My environment is:
Windows XP
PHP 5.2.5
DB2 Run-Time Client 8.2
IIS

I connect with the following code:

Code: Select all

 
    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>";
    }
 
I get the following error:
***didn't work db->Connect(dsn)
SQLSTATE: 42968
Message: [IBM][CLI Driver] SQL8002N Connect processing failed; a valid product license was not found. SQLSTATE=42968 SQLCODE=-8002
I know I am using the correct iSeries port, the correct DB name, and a fully licensed server. Has anyone ever seen this error?

Re: Connecting to a DB2 Database using PHP and ADOdb

Posted: Thu Nov 13, 2008 11:15 am
by RobertGonzalez
Before trying to connect with PHP try connecting with a client tool on the machinet to make sure you can actually connect with the proper credentials. Once you know you can connect with the client tools on the machine then step next into connecting with native PHP functions. Once those are known to work then start trying to use a library like adodb. Sometime the devil is in the details and there is a chance, however small, that it could be an issue with any of of these steps.

Re: Connecting to a DB2 Database using PHP and ADOdb

Posted: Fri Nov 14, 2008 1:41 pm
by repp9418
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.

Code: Select all

 
     include('adodb/adodb.inc.php');
     $db = ADONewConnection('odbc');
     $dsn = "DRIVER={iSeries Access ODBC Driver};SYSTEM=$Host;DATABASE=$DBName;PROTOCOL=TCPIP;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>";
     }
 

Re: Connecting to a DB2 Database using PHP and ADOdb

Posted: Fri Nov 14, 2008 2:08 pm
by RobertGonzalez
Awesome. Glad you got it sorted out.