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:

    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?

    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.

     
         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>";
         }
     
      5 months later

      Hi ,

      Thanks for ur code and solutions. I m a db2 newbie, with your code, I managed to connect to db2, but when the sql got huge returns rows. it will stop and didnt return me result. Any idea? Thanks

        6 days later

        Yes I had that problem as well. Below is my new configuration.

        include(EP_Root.'adodb/adodb.inc.php');
        $DB2Port = 446;              //Port
        $DB2dsn = "DRIVER={iSeries Access ODBC Driver};SYSTEM=$DB2Host;PROTOCOL=TCPIP;PORT=$DB2Port;"; //DB2 Connection String
        
        $dbdb2 = ADONewConnection('odbc');
        $dbdb2->Connect($DB2dsn,$DB2User,$DB2Password);
        $dbdb2->SetFetchMode(ADODB_FETCH_ASSOC);  //this line will return all results as an associative array
        
        $sql = "Select * from my_table";
        $rs = $dbdb2->Execute($sql);
        if ($rs and !$rs->EOF) {
        	$result = $rs->GetArray();
        	$rs->close();
        	foreach($result as $key=>$value) {
        		foreach($value as $k=>$v)
        		error_log("$k => $v");
        		error_log('***********************');
        	}
        }
        

        Hope this helps.

        Harmony

          a year later

          include('adodb/adodb.inc.php');
          $DB2Port = 23;
          $DB2Host = 'IP ADDRESS';
          //$DB2Host = 'Job123';
          $DB2User = 'job123';
          $DB2Password = 'job123';
          $DB2dsn = "DRIVER={iSeries Access ODBC Driver};SYSTEM=$DB2Host;PROTOCOL=TCPIP;PORT=$DB2Port;";
          $DB2db = ADONewConnection('odbc');
          echo "So far so good";
          if ($DB2db->Connect($DB2dsn,$DB2User,$DB2Password))

          When i try to execute this scripts i am getting the following error message

          Warning: odbc_connect() [function.odbc-connect]: SQL error: [IBM][System i Access ODBC Driver]Communication link failure. comm rc=10060 - CWBCO1048 - A firewall blockage or time-out occurred trying to connect to the System i, SQL state 08S01 in SQLConnect

            Write a Reply...