Hello

I would like to know what the procedure and the configuration options for connection a linux box running apache and php to db2 on an AS400.

I can't seem to find anywhere on the 'net
that provides a tutorial on what is required ( like do i need db2 for linux?? even though i'm connecting to db2 on as400)...

Any help or pointers to good docs,
will be much appreciated.

Marios

    I am also trying to find any information on this subject - Does anyone have any input?
    -Thanks,
    Ken

      I have been trying to do this for quite some time, and thanks to the Java support in PHP4, I have just recently been able to start accessing DB2/400.

      Unfortunately, it is not as easy as accessing other native database drivers. What I do is create Java "beans", which can access the AS/400 using the JDBC driver provided in the JT400 toolkit. I don't have a link handy to the toolkit, but I'm sure you can find it on IBM's site if you work with the AS/400...err, I mean iSeries eServer. :-)

      Once you have Java objects, which know how to access the 400, you can access the objects from PHP using the Java support, like $var= new new Java("com.my.object");.

      I am having problems with some of my objects not working after the first time. I think it has to do with how and when I load the as400 jdbc driver. Some work just fine. It might have to do with serialized objects...I am still getting up to speed with my bean programming so I am doing a lot of trial and error.

      I should probably setup a page or something with more documentation and examples. I am by no means an expert at this, but you are welcome to email me if you need more direction than I am able to provide in this forum.

      -Pete

        From what I've heard, you use the ODBC functions. Eventhough you aren't actually ODBCing (it uses native functions) this will allow you to access a 400 (iSeries).

        I did play around with this for a while with our S10/S20/720 but never did but it to a real test.

        Thanks,
        Brad Atkins

          The IBM-supplied Client Access ODBC drivers for NT work fine, and I've used them a fair amount, but I couldn't fine anything for Linux that really provided AS/400 connectivity.

            In PHP, when you compile "--with-ibm-db2" you are really binding
            the DB2 CLI methods (in the guise/naming convention of the odbc_
            calls).

            Same name, but not ODBC...DB2 CLI! You should be able to use
            IBM's DB2 Connect package, or run directly to a socket on the AS400
            box and talk CLI that way..even though you're calling odbc_connect
            and such.

            'Luck...

            -Szii

              You should be able to use IBM's DB2 Connect package, or run directly to a
              socket on the AS400 box and talk CLI that way.

              Now that's very interesting: is this available for Linux? The page you referred to elsewhere only mentioned OS/2 and Win32.

                Let me pre-qualify this with: "I've never done it myself"
                but if you think about what should be required, whether
                you run DB2 CLI from OS/2, Windows, or Linux all you're
                doing is opening up a socket and using a specific protocol.
                The AS400 should act in the same manner - open up a socket
                and talk CLI to it. Once you compile --with-ibm-db2 you've
                gained the ability to talk CLI. Point it at a waiting AS400
                and it "should" work.

                All of the above, as I said, is theory - I've never done it myself
                but I can't think of why it wouldn't work. Whether your target
                box is an AS400, or BeOS it's still just CLI over a socket interface.

                'Luck!

                -Szii

                  After much searching on the 'net. I found this article at
                  http://www.faqts.com/knowledge_base/view.phtml/aid/5613/fid/12

                  I followed everything to the letter and i get a message about valid license not found, when i do a connect to PHP_DBNAME etc (step 4). Now is the licence on the as400 or on my linux box. But i have the personal edition of db2, so what's up. Compiling and making all the way including apached worked just fine.

                  Anybody got ideas? I've looked at iODBC, openlink etc and seems a bit flaky( have to do stuff to the as400). I'm leaning now towards maybe calling Java objects. Anybody got any places on the 'net were it explains how to instantiate java objects and use them via php?

                  Thanks
                  Marios

                    The licensing for DB2 Personal Edition is
                    1 machine, one developer - no remote clients.

                    As for connecting, you can use iODBC, or
                    unixODBC for "real" programs. When you use PHP and compile --with-ibm-db2 you'll get
                    "ODBC calls which map and make DB2 CLI calls under the covers" and you'll bypass ODBC and
                    the performance hit associated with ODBC vs.
                    DB2 CLI. ie, odbc_connect() in PHP LOOKS like ODBC, but it really makes DB2 CLI calls
                    and doesn't need/use/require ODBC at all.

                    'Luck!

                    -Szii

                      Thanks for the reply. So why is it giving me
                      a licence not valid......I'm "trying" to connect to a AS400 remotely from a linux box with apache and php. The ibm-db2 switch with php seems to work as phpinfo reports it so.

                      If I can't get DB2 CLI to work then iODBC might be the way. But then do i compile php with ibm-db2 and iODBC support?....and is the ODBC for linux driver in the Personall Edition of DB2 included?

                      thanks
                      marios

                        Erg, this is really getting annoying.

                        Okay, LAST TIME!

                        --with-ibm-db2 DOES NOT USE ODBC!
                        When you say "odbc_connect()" IT DOES NOT
                        USE ODBC! PERIOD! YOU say "ocbc_connect()"
                        and IT says "CLIConnect!"

                        The function NAMES say odbc_xxxx but
                        it's NOT USING ODBC!

                        Setup DB2Connect on your remote machine,
                        run the "db2 catalog" commands, and
                        use TCP/IP to talk to the AS400! You don't
                        need iODBC/unixODBC/etc at all.

                        Do a search in the DB2 docs...there's a whole DRDA section about communications between client yyyy and an AS400.

                        Peace, love, code.

                        -Szii

                          On the subject of licensing, the Personal Edition does not allow for remote clients.
                          (At least that's my interpretation of the
                          DB2 site.) There's a db2licm executable
                          somewhere on your CD. That same CD should
                          contain the license itself. Use the db2licm
                          to add the license from the CD.

                          'Luck!

                          -Szii

                            3 months later

                            Original Message:

                            Author: Kirk Parker (209.191.185.54)
                            Date: 2000-12-29 02:01:50

                            The IBM-supplied Client Access ODBC drivers for NT work fine, and I've used them a fair amount, but I couldn't fine anything for Linux that really provided AS/400 connectivity.

                            Hello Kirk,

                            I'm trying to do the same,
                            Could you please tell me how you did it through ODBC with Client Access.

                            HAVE YOU SOME CODE EXAMPLE.

                            Thanks.

                            Alim.

                              6 months later

                              Mario,

                              Were you able to resolve this probelm regarding the licence issue.

                              I'm at the same point myself and haven't found the answer

                              -Paul

                                I reinstalled everything and did the whole procedure again.

                                Didn't need a license key. I assume it had to do with the commands entered to via CLI to connect to DB2. Review the commands entered, otherwise I've written a small recipe to get this to work from my experience, might help, mail me privately if you would like me to send it you.

                                marios

                                  The LicenseError message should not occur - if it happens, it means you have installed the DB2 portion incorrectly. There is a VERY GOOD tutorial at: http://www.e-gineer.com/instructions/installing-ibm-db2-for-php4x-with-apache13x-on-linux.phtml

                                  I have (after much trouble-shooting) - installed Apache/PHP4/DB2connect - on RedHat6.2 - and Im going through a Firewall to a corporate AS400 - passing data back and forth in real-time for a commercial web application. It works fine. the instructions found at the tutorial above were a big help.

                                  If you follow the tutorial above and still have a major problem, post here and I will try to help you out.
                                  -Ken

                                    Ken,

                                    I've tried using the mentioned tutorial...

                                    I can connect to the sample database that I create with db2 on my linux box but when I try to connect to a remote AS/400 box I get the Licence error.

                                    I planning on removing the DB2 connect software again and trying from scratch.

                                    From what I can tell the AS/400 side is configured properly. I can connect to it from a Win 2000 box running apache and php. Using the IBM ODBC connect driver.

                                      Paul - if you intend to use the FREE DB2connect client - You CANNOT install the DB2 server product on the same machine - that is why you will get the license error. You must delete ALL DB2 software and install only the DB2connect software.
                                      =-=-=-=-=-=-=-=-=-=-=-=-=-=
                                      Here is an install tutorial for the DB2 part
                                      Note: I made the AS400 user account/login to match the db2inst1 user on the linux machine.

                                      Thanks to: Derek Piper for this info.

                                      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 given defaults, pick an original password at least.

                                      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 based on what is required.

                                      Variables:

                                      [localName] The local name you want to call this instance
                                      [as400Addr] IP Address of your AS/400
                                      [youras400DB] Regular host name of your AS/400
                                      [as400DB] What you want to call the AS/400 on the DB2/Linux side
                                      [DSN] What you plan to have as the ODBC DSN within PHP
                                      [as400user] User with adequate permissions and CCSID*
                                      [as400pass] Password of user

                                      • CCSID is for character handling, you might want to set this to 037 for [as400user] and use the command below with BIDI in. Incorrect settings on eithe end can mean you can't log in even if the password is correct.

                                      Commands (enter step-by-step on one line):

                                      catalog tcpip node asnode remote 209.27.120.134 server 446
                                      catalog tcpip node [localName] remote [as400Addr] server 446 remote instance [youras400] system www ostype OS400

                                      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