PHP/Linux 到 AS/400-db2 [英] PHP/Linux to AS/400-db2
问题描述
我正在尝试让 php 在 Linux Centos 服务器上访问为/400 (iSeries) db2 数据库.
我尽可能多地使用这个 IBM 指南(尽管我们无法让 GUI 配置实用程序正常工作.)
http://www-03.ibm.com/systems/i/soft...ide/index.html
我下载并成功安装了 iSeriesAccess 驱动程序和先决条件.
<上一页>rpm -i iSeriesAccess-5.4.0-1.6.i386.rpm我已配置这些文件来定义驱动程序/DNS:
/etc/odbc.ini 和/etc/odbcinst.ini
<上一页>[iSeries Access ODBC 驱动程序]说明 = iSeries Access for Linux ODBC 驱动程序驱动程序 =/opt/ibm/iSeriesAccess/lib/libcwbodbc.so设置 =/opt/ibm/iSeriesAccess/lib/libcwbodbcs.soDriver64 =/opt/ibm/iSeriesAccess/lib64/libcwbodbc.soSetup64 =/opt/ibm/iSeriesAccess/lib64/libcwbodbcs.so线程 = 2不要DLC关闭 = 1使用次数 = 1文件/etc/odbc.ini 是空的,所以我添加了这个配置:
<上一页>[AS400]说明 = iSeries Access ODBC 驱动程序驱动程序 = iSeries Access ODBC 驱动程序系统 = 172.999.999.999(来自 netstat 选项 1)用户 ID = my_user密码 = my_pass命名 = 0DefaultLibraries = QGPL数据库 =连接类型 = 0提交模式 = 2扩展动态 = 1DefaultPkgLibrary = QGPLDefaultPackage = A/DEFAULT(IBM),2,0,1,0,512允许数据压缩 = 1图书馆视图 = 0AllowUnsupportedChar = 0强制翻译 = 0迹线 = 1DSN = AS400我认为这些工作正常,因为我可以运行
<上一页>isql -v AS400并且我成功连接到 db2 数据库可以从 Linux 机器执行查询.
但是,我无法在 Linux 机器上的 PHP 中获得 make 和 ODBC 连接.是否有另一种方法可以从 php 测试 DSN?或获取更详细的错误信息?
<上一页>$server="172.999.999.999";//尝试使用系统名称和AS400",dsn 名称$user="my_user";$pass="my_pass";$conn=odbc_connect($server,$user,$pass);if ($conn == false) {echo "无法连接数据库...";}
结果:
<上一页>**无法连接到数据库...**phpinfo() 显示 php 是用 unixODBC 编译的,并且 unixODBC 已启用.
感谢任何帮助!
尝试仔细检查您的 odbcinst.ini 和 odbc.ini 配置文件.您是否在 odbc.ini 中设置了正确的数据库名称/默认库?我按照这些说明成功了:
http://werk.feub.net/2010/11/ingredients-php-db2-and-unixodbc/
一个不同之处是我找到了一个包含 libXm.so.3 的 openmotif 版本.
http://rpm.pbone.net/index.php3/stat/3/limit/2/srodzaj/1/dl/40/search/libXm.so.3/field[]/1/field[]/2
安装php-odbc后重启apache.
/etc/odbc.ini
[ISERIES]说明 = iSeries 的 iSeries Access ODBC 驱动程序 DSN驱动程序 = iSeries Access ODBC 驱动程序系统 = 192.168.1.1用户 ID = MYUSER密码 = MYPASSWORD命名 = 0DefaultLibraries = QGPL数据库 =连接类型 = 0提交模式 = 2扩展动态 = 0DefaultPkgLibrary = QGPLDefaultPackage = A/DEFAULT(IBM),2,0,1,0,512允许数据压缩 = 1图书馆视图 = 0AllowUnsupportedChar = 0强制翻译 = 0跟踪 = 0
示例 PHP:
I am trying to get php on Linux Centos server access as/400 (iSeries) db2 database.
I am using this IBM guide as much as possible, (though we could not get GUI configuration utility working.)
http://www-03.ibm.com/systems/i/soft...ide/index.html
I downloaded and successfully installed iSeriesAccess drivers and pre-requisites.
rpm -i iSeriesAccess-5.4.0-1.6.i386.rpm
I have configured these files to define drivers/DNS:
/etc/odbc.ini and /etc/odbcinst.ini
[iSeries Access ODBC Driver] Description = iSeries Access for Linux ODBC Driver Driver = /opt/ibm/iSeriesAccess/lib/libcwbodbc.so Setup = /opt/ibm/iSeriesAccess/lib/libcwbodbcs.so Driver64 = /opt/ibm/iSeriesAccess/lib64/libcwbodbc.so Setup64 = /opt/ibm/iSeriesAccess/lib64/libcwbodbcs.so Threading = 2 DontDLClose = 1 UsageCount = 1
file /etc/odbc.ini was empty so I added this configuration:
[AS400] Description = iSeries Access ODBC Driver Driver = iSeries Access ODBC Driver System = 172.999.999.999 (from netstat option 1) UserID = my_user Password = my_pass Naming = 0 DefaultLibraries = QGPL Database = ConnectionType = 0 CommitMode = 2 ExtendedDynamic = 1 DefaultPkgLibrary = QGPL DefaultPackage = A/DEFAULT(IBM),2,0,1,0,512 AllowDataCompression = 1 LibraryView = 0 AllowUnsupportedChar = 0 ForceTranslation = 0 Trace = 1 DSN = AS400
I assume these are working because I can run
isql -v AS400
and I connect successfully to db2 database can perform queries from Linux box.
However I have been unable to get make and ODBC connection in PHP on the Linux box. Is there another way to test DSN from php? or get more detailed error information?
$server="172.999.999.999"; // tried with both system name and "AS400", the dsn name $user="my_user"; $pass="my_pass"; $conn=odbc_connect($server,$user,$pass); if ($conn == false) { echo "Not able to connect to database...
"; }
result:
**Not able to connect to database...**
phpinfo() shows that php was compiled with unixODBC and unixODBC is enabled.
any help is appreciated!
Try double checking your odbcinst.ini and odbc.ini config files. Do you have the correct database name/default library set in odbc.ini? I had success following these instructions:
http://werk.feub.net/2010/11/ingredients-php-db2-and-unixodbc/
One difference is that I found a version of openmotif that included libXm.so.3.
http://rpm.pbone.net/index.php3/stat/3/limit/2/srodzaj/1/dl/40/search/libXm.so.3/field[]/1/field[]/2
Restart apache after installing php-odbc.
/etc/odbc.ini
[ISERIES]
Description = iSeries Access ODBC Driver DSN for iSeries
Driver = iSeries Access ODBC Driver
System = 192.168.1.1
UserID = MYUSER
Password = MYPASSWORD
Naming = 0
DefaultLibraries = QGPL
Database =
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
Sample PHP:
<?php
if (!$db = odbc_connect ( "ISERIES", "MYUSER", "MYPASSWORD") )
echo 'error!';
$result = odbc_exec($db, "SELECT * FROM MYUSER.TABLENAME");
while (odbc_fetch_row($result)) {
echo odbc_result($result, "ID")."
";
}
odbc_close($db)
?>
这篇关于PHP/Linux 到 AS/400-db2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!