Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
583 views
in Technique[技术] by (71.8m points)

odbc - PHP/Linux to AS/400-db2

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!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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)
?>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...