[RESOLVED] PHP to DB2 connection issue (as/400, iSeries, db/400)
Results 1 to 5 of 5

Thread: [RESOLVED] PHP to DB2 connection issue (as/400, iSeries, db/400)

  1. #1
    Member
    Join Date
    Sep 2007
    Location
    PA
    Posts
    31

    resolved [RESOLVED] PHP to DB2 connection issue (as/400, iSeries, db/400)

    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 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:
    Code:
    ***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?

  2. #2
    Member
    Join Date
    Sep 2007
    Location
    PA
    Posts
    31
    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 Code:
         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>";
         } 

  3. #3
    Junior Member
    Join Date
    Apr 2009
    Posts
    1
    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

  4. #4
    Member
    Join Date
    Sep 2007
    Location
    PA
    Posts
    31

    PHP DB2 result set arrays

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

    PHP Code:
    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

  5. #5
    Junior Member
    Join Date
    Aug 2010
    Posts
    1
    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

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •