Successfully connect to DB2 using PHP NOT using ODBC?

…衆ロ難τιáo~ 提交于 2019-12-11 02:14:09

问题


Need to know if 1) anyone successfully made a connection and 2)queried a remote DB2 server using PHP, and 3) if so how?

I installed the PECL extension for db2

[db2] extension=ibm_db2.so

but can't figure out how to use it. All the examples I find use ODBC style dsn, I don't want to use ODBC.

UPDATE: According to documentation here (http://www.redbooks.ibm.com/abstracts/sg247218.html) it is nominally possible to use the ibm_db2 driver (sans ODBC) but the methodology described therein is either incomplete or outdated.


回答1:


Using PHP you only have one option: ODBC.

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)

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                  = 0
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);



回答2:


For DB2 LUW you'll need to install, at the minimum, the appropriate version of the DB2 Data Server Driver for ODBC and CLI from here. It supplies the required libraries used by the PHP module.




回答3:


You can use the pecl ibm_db2 extension. It uses DB2 Call Level Interface (DB2 CLI), so you must have IBM db2 CLI installed in your system.

This is the PHP DOC page:

http://php.net/manual/pt_BR/intro.ibm-db2.php



来源:https://stackoverflow.com/questions/17997669/successfully-connect-to-db2-using-php-not-using-odbc

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!