使用PHP成功连接到DB2而不使用ODBC? [英] Successfully connect to DB2 using PHP NOT using ODBC?

查看:139
本文介绍了使用PHP成功连接到DB2而不使用ODBC?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

需要知道1)是否有人成功建立了连接,2)是否使用PHP查询了远程DB2服务器,以及3)如何?

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

我安装了db2的PECL扩展名

I installed the PECL extension for db2

[db2]
extension = ibm_db2.so

但无法弄清楚如何使用它。我发现的所有示例都使用ODBC风格的dsn,但我不想使用ODBC。

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.

更新:根据此处的文档( http://www.redbooks.ibm.com/abstracts/sg247218.html ),名义上可以使用ibm_db2驱动程序(没有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.

推荐答案

使用PHP您只有一个选择:ODBC

Using PHP you only have one option: ODBC.

这里是有关如何在Ubuntu上连接到DB2 for i(在IBM i上)的逐步说明:

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

从IBM下载免费的iSeriesAccess-6.1.0-1.2.i386.rpm文件(您必须创建一个免费帐户才能获得它)

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)

将RPM文件转换为Ubuntu可以理解的内容: sudo Alien iSeriesAccess-6.1.0-1.2.i386.rpm

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

安装生成的.deb: sudo dpkg -i iseriesaccess_6.1.0-2.2_i386.deb

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

复制已安装的iS到Ubuntu期望的位置的库: sudo cp / opt / ibm / iSeriesAccess / lib / * / usr / lib

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

编辑/etc/odbc.ini文件以包含:

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

编辑/etc/odbcinst.ini文件以包含:

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

然后使用PDO创建连接:

And then to create the connection with PDO:

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

这篇关于使用PHP成功连接到DB2而不使用ODBC?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆