Umm.. okay. I might not be good at explaining this but I'll try.
The information I found out came from a nice guy called Remo whom I found had written these steps in an email. We emailed back and forth for a while about it and I had success with reading data off the AS/400. Unfortunately we both had the same problem in being unable to insert/update/delete records so I don't know if that will ever get sorted out. Still, you can read data off the AS/400 using SELECT statements.
Okay.. so, my notes that I made about it.
IBM AS/400 DB2 Connect to Linux Apache/PHP
Install DB2 Connect Personal (or Enterprise) Edition on Linux WWW machine.
Compile PHP with DB2 Support (for appropriate version - the example given is for version 7.1).
Add this option to your PHP compile options
--with-ibm-db2=/usr/IBMdb2/7.1/include/
Create DB2 Instance on Linux machine. Use the 'db2setup' command in the 'install' subdirectory of the DB2 Connect installation. Set up the account but not with the defaults, pick an original password at least.
e.g.
user db2as400
password ?????
Set up a user on the AS/400 and keep username and password for later to use in place of [as400user] and [as400pass]. Set that user's CCSID to '037' (for USA), do not leave it at 65535 (possibly system default). Make sure permissions are correct for any tables that need to be read or written to.
Configure DB2 Instance by logging into Linux machine as DB2 user and password (as defined above) (or by su'ing from root to db2 account). Use command 'db2' to enter command line processor. From there, type (on one line per statement):
(Items in [] are the user definable settings - don't include the [], just make up different names that are unique)
catalog tcpip node [localName] remote 192.168.4.4 server 446 remote instance [youras400] system www ostype OS400
catalog dcs database [as400DB] as [youras400]
or
catalog dcs database [as400DB] as [youras400] parms ",,,,,,,,BIDI=037"
catalog database [as400DB] as [DSN] at node [localName] authentication DCS
connect to [DSN] user [as400user] using [as400pass]
bind /usr/IBMdb2/V7.1/bnd/@ddcs400.lst BLOCKING ALL SQLERROR CONTINUE MESSAGES DDCS400.MGS GRANT PUBLIC
connect reset
terminate
Example PHP and SQL code:
$sql = "SELECT * FROM AS400LIBRARY.AS400FILE";
if ($conn_id = odbc_connect("[DSN]", "[as400user]", "[as400pass]")) {
if ($result=odbc_do($conn_id, $sql)) {
odbc_result_all($result);
odbc_free_result($result);
} else {
echo "cannot execute '$sql'<br>";
}
odbc_close($conn_id);
} else {
echo "can not connect to DSN: $dsn<br>";
}
You should then be able to retrieve data from the AS/400 using normal SQL SELECT commands. Note that the library that the AS/400 file is in has to be in every statement.