我试图在
Linux Centos服务器上访问PHP作为/ 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 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
[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,1,512 AllowDataCompression = 1 LibraryView = 0 AllowUnsupportedChar = 0 ForceTranslation = 0 Trace = 1 DSN = AS400
我认为这些都有效,因为我可以跑
isql -v AS400
但是我无法在Linux机器上的PHP中获得make和ODBC连接.
还有另一种方法可以从PHP测试DSN吗?或获取更详细的错误信息?
$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...
"; }
结果:
**Not able to connect to database...**
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] 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),512 AllowDataCompression = 1 LibraryView = 0 AllowUnsupportedChar = 0 ForceTranslation = 0 Trace = 0
示例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")."\n"; } odbc_close($db) ?>