1

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?

Cœur
  • 37,241
  • 25
  • 195
  • 267
  • I may be mistaken, but you'll probably be less frustrated if you switch to PDO. Plus your code will be more versatile, which would bring more of the value you want to provide your new team. – Anthony Dec 08 '14 at 20:39
  • 1
    Buck's answer may be all you need to get things working; at the very least it's a necessary first step, because you have to use the right driver. Once you can connect successfully, I suspect you will be able to be productive in very short order using PHP. However, I just wanted to say you shouldn't be afraid of RPG. I think you will be able to pick it up reasonably quickly. It's a straightforward language, especially if all you're doing is accessing the database (doing green screen displays can get trickier). – John Y Dec 08 '14 at 21:55
  • @Anthony I am looking into PDO and believe that's how I got things to work finally. –  Dec 09 '14 at 21:09
  • @JohnY I am not opposed to RPG outside of documentation does not seem to be as readily available as other languages, unless you want to fork over some money for books. Additionally, they have a heavy amount of green screen and procedures running in RPG. I will have to start supporting those and that's the section I'm having a harder time with. The DB stuff I think I have figured out. –  Dec 09 '14 at 21:12
  • It's true there aren't as many freely available resources for learning RPG as for more mainstream languages; but if you like classic, old-school, comprehensive-but-dry manuals, IBM's are among the best, and they're available as free PDFs (see the [Programmer's Guide](http://www-01.ibm.com/support/knowledgecenter/ssw_ibm_i_71/rzahg/rzahgrpgprogpdf.htm) and [Language Reference](http://www-01.ibm.com/support/knowledgecenter/ssw_ibm_i_71/rzahg/rzahgrpglangrefpdf.htm), as well as a bunch of other languages/topics in the left navigation pane). – John Y Dec 09 '14 at 21:35

1 Answers1

4

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};

Buck Calabro
  • 7,558
  • 22
  • 25
  • 1
    Thanks, I finally got it to use the iSeries Access ODBC Driver, but was only able to use PHP ODBC_CONNECT. I got the impression it's better to use DB2_CONNECT over ODBC. –  Dec 09 '14 at 21:08