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

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

问题描述

需要知道 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]扩展=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

将已安装的 iSeries 库复制到 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 不使用 ODBC 成功连接到 DB2?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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