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")."\n";
}
odbc_close($db)
?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With