Php/Linux to As/400-Db2

Connecting to an IBM AS/400 DB2 Database

Your odbcinst.ini file is saying to use the MySQL ODBC driver:

Driver = /usr/lib/x86_64-linux-gnu/odbc/libmyodbc.so

but you need to use the iSeries Access ODBC driver. The reason you're getting an Access Denied for User message is because you're trying to connect to your MySQL database with credentials for the IBM i.

Here are step by step instructions for how to connect to DB2 for i (on the IBM i) on Ubuntu:

Download the free iSeriesAccess-6.1.0-1.2.i386.rpm file from IBM (you'll have to create a free account to get it - and I'm sure there is a more recent version than 6.1.0-1.2)

Convert the RPM file to something Ubuntu understands: sudo alien iSeriesAccess-6.1.0-1.2.i386.rpm

Install the resulting .deb: sudo dpkg -i iseriesaccess_6.1.0-2.2_i386.deb

Copy the installed iSeries libraries to where Ubuntu expects them: sudo cp /opt/ibm/iSeriesAccess/lib/* /usr/lib

Edit the /etc/odbc.ini file to contain:

[primary]
Description = primary
Driver = iSeries Access ODBC Driver
System = IP_ADDRESS
UserID = USERNAME
Password = PASSWORD
Naming = 1
DefaultLibraries = QGPL
Database = XXXXXXXXXX
ConnectionType = 0
CommitMode = 2
ExtendedDynamic = 0
DefaultPkgLibrary = QGPL
DefaultPackage = A/DEFAULT(IBM),2,0,1,0,512
AllowDataCompression = 1
LibraryView = 0
AllowUnsupportedChar = 0
ForceTranslation = 0
Trace = 0

Edit the /etc/odbcinst.ini file to contain:

[iSeries Access ODBC Driver]
Description = iSeries Access for Linux ODBC Driver
Driver = /usr/lib/libcwbodbc.so
Setup = /usr/lib/libcwbodbcs.so
NOTE1 = If using unixODBC 2.2.11 or later and you want the 32 and 64-bit ODBC drivers to share DSN's,
NOTE2 = the following Driver64/Setup64 keywords will provide that support.
Driver64 = /usr/lib/lib64/libcwbodbc.so
Setup64 = /usr/lib/lib64/libcwbodbcs.so
Threading = 2
DontDLClose = 1
UsageCount = 1

And then to create the connection with PDO:

$pdo = new PDO("odbc:DRIVER={iSeries Access ODBC Driver};SYSTEM=$server;PROTOCOL=TCPIP", $username, $password);

PHP to AS400 Connection via ODBC/PDO error from browser

OK, I found the solution and I'll post it for anyone who needs it.

Creating a symbolic link to the driver files in /usr/lib/ solves the issue.

sudo ln -s /opt/ibm/iSeriesAccess/lib64/* /usr/lib/*

After that Apache/PHP will be able to locate the file without hiccups.

Hope it helps.

How to connect AS400 with Laravel

For PHP and Laravel it is wise to get the unixODBC working at the command line before trying to get it working with PHP. The reason is that troubleshooting is easier when you have fewer components to test. It also helps with separation of responsibilities.

The solution was to download and install
a suitable Db2-driver for ODBC/CLI on Linux specifically to work with i-series (AS/400) from IBM website at this link.

The other small footprint clidriver (supplied by IBM) cannot communicate with i-series unless you go via a Db2-connect gateway or have a Db2-connect licence (separate purchase). So it is usually more effective to use the IBM i access product instead. The clidriver works correctly without needing a license or Db2-connect, only when the target Db2-server runs on Linux or Unix variant or Microsoft Windows.

This IBM i access client product has a PDF document included "Installation and Usage Guide" which has helpful information, and several links to useful resources.

After installation, it is necessary to properly configure both the odbcjinst.ini (which details the driver) and the odbc.ini(which details the data soruces) (or .odbc.ini for user DSNs) for use with the driver supplied by the IBM i access client product.

Instructions for completing the odbcinst.ini and odbc.ini are available on the unixODBC website.

Test the connection to the i series with the isql tool, to verify that unixODBC is able to connect and use SQL queries.

The IBM i access product also has troubleshooting tools that includes cwbping and cwbtrc commands among others, which exercise the Db2-driver independently of unixODBC.

Once isql successfully connects to the i series database, you are now ready to configure PHP to use the driver in the normal way. You can then test with Laravel.

Remember to ensure that your linux shell sets the correct LANG environment variable to match your country and your character encoding before accessing the database (which require the relevant locale to be installed), otherwise codepage conversion may give unexpected results.

Connect PHP to IBM i (AS/400)

Have you looked at connecting to the server using unixODBC? If I remember correctly it has support for IBM DB2 and compiles on OpenBSD. Check out http://www.php.net/odbc for more information regarding the PHP side.

If you can't get that to work, the option to setup a web service on a Linux server may be all you can do.

Is the available db2 express on IBM is similar as DB2 for IBM i (db2/as400) green screen uses?

All three major DB2 platforms (z/OS, i, and LUW) share enough common SQL syntax to make cross-platform application development an approachable goal. It's worth pointing out that the current edition of IBM's SQL Reference for Cross-Platform
Development contains over a thousand pages.

IBM Data Studio, a no-cost IDE based on Eclipse, is capable of running SQL statements, browsing database objects, and developing stored procedures on every DB2 platform. It is a separate download from DB2 servers and clients.

Unlike cross-platform DML, which is largely identical, an application's underlying DDL could differ considerably between DB2 for i and DB2 LUW, the platform/family to which DB2 Express-C belongs.

Cross-platform DB2 connectivity is most easily accomplished via IBM's JDBC Type 4 driver, but it might not be practical for PHP. Accessing DB2 for i (and z/OS) over other protocols requires an extra piece of software called DB2 Connect.



Related Topics



Leave a reply



Submit