DB 2 PDOIBM

DB2 Connect access only …

Goto Main Page

Who is this page for?

Instructions designed for IBM i developer learning PHP starting from ground zero …

  • … installing PHP on a laptop
  • … little control over IBM i machine (can’t install Zend Server on IBM i)
  • … but have a DDM/DRDA connection to IBM i (good enough)

Prerequisites

On IBM i …

  • recent IBM i {DB2 PTFs} or clobs will fail (PHP pdo_ibm drivers)

On laptop …

Check your IBM i configuration

InfoCenter


1) WRKRDBDIRE - find tcp connection
2) WRKTCPSTS - check *DDM is running
3) STRTCPSVR SERVER(*DDM) - start DDM if not running

1) WRKRDBDIRE - find tcp connection (example: *LOCAL is LP0264D)

WRKRDBDIRE


WRKRDBDIRE *LOCAL name (LP0264D) may not match your tcp name (lp0164d.rch.stglabs.ibm.com). If the names do not match use the short name in your connection and catalog PDO(“ibm:C1E0CD143″,”MYUID”,”MYPWD”, array(PDO::ATTR_AUTOCOMMIT=>true)). Using a serial number is REALLY annoying thing IBM i ships by default for *LOCAL, so almost everyone deletes serial number entry and changes *LOCAL to match TCP name (sigh, yes i changed mine).

I am using iASP for my Zend Server machine configuration (MYASP2), so PDO(“ibm:MYASP2″,”MYUID”,”MYPWD”, array(PDO::ATTR_AUTOCOMMIT=>true)) is a valid DB2 “independent/isolated” connection.

I also have other IBM i machines configured remote (LP0164D and LP0364D), PDO(“ibm:LP0164D or LP0364D”,”MYUID”,”MYPWD” array(PDO::ATTR_AUTOCOMMIT=>true)) is a valid DB2 “remote” connection.

2) WRKTCPSTS - check *DDM is running

DDM


3) If not running use STRTCPSVR SERVER(*DDM). Communication DRDA is port 446 (NOT 8471).

Configure DB2 Connect

DB2 Connect


1) db2licm -l - check your license
2) db2 catalog - catalog your IBM i machine

Have db2 utility??

1) Use the db2 command line (if included in download)
========
db2 connect 10.5+
db2inst2 -> linux install db2 connect instance
lp0364d -> IBM i
========

>su db2inst2
>db2
db2 => catalog tcpip node LP0364D remote lp0364d.rch.stglabs.ibm.com server 446
db2 => catalog db LP0364D at node LP0364D authentication dcs
db2 => catalog dcs db LP0364D as LP0364D
db2 => terminate
Note: "LP0364D" - can be found using WRKRDBDIRE (local RDB name / database name)

ERROR: if you see SQL0805N  Package "NULLID.SYSSH000" was not found

>su db2inst2
$ db2
db2 => connect to lp0364d user db2 using xxxxx 
db2 => bind "/opt/ibm/db2/V10.5/bnd/@db2cli.lst" blocking all grant public
db2 => terminate
Note: On IBM i CRTLIB NULLID (if not exist, before bind)


Use db2 test your connection.
> db2 connect to LP0264D user myUid using myPassword

If db2 catalog fails, likely you need to install missing license.
> db2licm -l
> db2licm -a db2/license/license_filename

Not have db2 utility??

1) or packages without db2 utility
> edit /opt/ibm/cli/cfg/db2cli.ini
[LP0164D]
Database=LP0164D
Protocol=tcpip
Hostname=lp0164d.rch.stglabs.ibm.com
Servicename=446

2) If db2 catalog fails (db2cli.ini), likely you need to install missing license.
> ls /opt/ibm/cli/license (wherever db2 installed)
> cd /opt/ibm/cli/license (wherever db2 installed)
> unzip DB2_CUEi_QS_Activation_97.zip  (licence zip file you purchased)

more DB2 Connect configuration (if you need help)

DB2 Connect instructions click here {Linux DB2 Connect}.

If db2 connect is working, there is a good chance that PHP pdo_ibm will be working.

<?php
try { $db = new PDO("ibm:LP0264D","MYUID","MYPWD" array(PDO::ATTR_AUTOCOMMIT=>true));
if (!$db) throw new Exception(‘foo’);
} catch( Exception $e ) { die(“Bad connect: $database,$user”); 
} 
?>

Run to IBM i

On your laptop create these files for testing via Zend Studio (or Apache, or command line)..