1
votes

I am trying to get a PDO connection (php 5.4) on Windows 7 (64 bit) to connect to iSeries IBM AS/400. My end goal is to use Yii2, which uses PDO.

For PDO driver compatibility, I used php5.4, since php5.5 couldn't load the PDO extension for IBM_DB2. I originally had the the IBM DB2 odbc driver running with PDO, using the following connection string:

 try {
  $dbc = new PDO("ibm:DRIVER={IBM DB2 ODBC DRIVER};
         DATABASE=MYDB;"."HOSTNAME=myhost;", "myuser", "mypassword");
 } catch (PDOException $e) {
     print "Error!: " . $e->getMessage(). "<br/>";
     die();
 }

...but I was getting connection errors from the host. Maybe that is the wrong driver for iSeries?

I then found an iSeries Access ODBC driver in the install for IBM i Access for Windows, and thought this might be the driver needed instead. I had to do a system restore to get the iSeries Access ODBC driver working, but the restore uninstalled the other IBM DB2 ODBC driver. The iSeries Access ODBC driver now appears correctly.

However, now the PDO extension failed to load. It complained about db2cli.dll missing. In trying to fix thsi, it also re-installed the old IBM DB2 ODBC driver connection. Note: I am still getting the error message.

1) Will the IBM DB2 ODBC driver work with iSeries, and I just have the connection string wrong?

2) Does the missing db2cli.dll message indicate the PDO connectivity is indeed tied to the IBM DB2 ODBC driver? I am wondering if the iAccess ODBC driver can/should be used with the PDO extension.

Any help is appreciated. Thank you.

1
See if this existing answer helps: stackoverflow.com/questions/19184302/… - mustaccio

1 Answers

2
votes

Both ODBC drivers are required, and the connection string is wrong.

1) To get rid of the db2cli.dll message, the odbc cli drivers had to be downloaded from IBM (in addition to the Client Access 7.1.zip for iSeries ODBC drivers), and then the path had to be updated manually to point to the db2cli.dll file.

2) The connection string is as follows: (include the curly brackets)

$dbc = new PDO("odbc:DRIVER={iSeries Access ODBC DRIVER}; ", 
    "SYSTEM={foobar}; ",  
    "DATABASE={dbname}; ", 
    "UID={foo}; ", 
    "PWD={bar}");