Search code examples
phpwindowsibm-midrangedb2-connect

PHP DB2_Connect issue to AS400 on Windows 7


New job, new department and they do everything on an as/400. Since I know nothing about RPG IV, I'm hoping to use my PHP knowledge to be of use to the team.

I'm trying to get PHP to connect to the as/400, here's my code:

<?php
$database = '*****';
$user = '*****';
$password = '*****';
$hostname = '*****';
$port = 446;

$conn_string = "DRIVER={IBM DB2 ODBC DRIVER};DATABASE=$database;HOSTNAME=$hostname;".
"PORT=$port;PROTOCOL=TCPIP;UID=$user;PWD=$password;";
$conn = db2_connect($conn_string,'','');

if ($conn) {
echo "Connection succeeded.";
db2_close($conn);
}
else {
echo "Connection failed.<br />";
echo db2_conn_error()."<br />";
echo db2_conn_errormsg()."<br />";
}
?>

There error message I get back is the following:

Connection failed. 42968 [IBM][CLI Driver] SQL8002N An attempt to connect to a host failed due to a missing DB2 Connect product or invalid license. SQLSTATE=42968 SQLCODE=-8002

Now, I'm running Apache 2.4 server on my laptop, with PHP 5.5, the IBM_db2 extension loaded is 1.9.6. The company laptop has IBM i Access for Windows installed on it, as well as a few IBM developer software packages. I would assume I'm not missing anything else from the laptop ... What am I missing?


Solution

  • DB2 for i is a different dialect than DB2 for LUW (or z/os). You need to use the client access driver instead of the IBM DB2 ODBC driver. DRIVER={iSeries Access ODBC Driver};