ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Stage 2 : Getting Connected

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Stage 2 : Getting Connected

    Frustration can be good...and bad!

    In my previous post, I was eluding to the frustration of getting onto the system and beginning the reality of connecting and doing something with data already on the system. To my happiness, I found things to be much more enjoyable than it was earlier.

    Getting connected was just some trial and error on my part. Permissions, UserID, Passwords (buying the System Admin a beer) -- you know, doing whatever it takes!

    This brought me to a quick and easy execution of a SQL statement on the Host:

    PHP Code:
    <?php

    $i5_server_ip 
    "localhost";
    $i5_uname     "UserName";
    $i5_pass      "Password";

    $conn i5_connect($i5_server_ip$i5_uname$i5_pass);
    if (
    $conn === false)
    {
       print (
    "FAIL : Failed to connect to server : $i5_server_ip,
                                   with user name : 
    $i5_uname
                               and password : 
    $i5_pass <br>\n");
       
    $errorTab i5_error();
       
    var_dump($errorTab);
       die();
    }  else {
       echo 
    "We have connection to the System : $i5_server_ip <br><br>\n";
    }

    $Store 3301;

    $qry "Select StrNum, StrNam, StPhon from Library/Stores Where STRNUM=?";
    $req i5_prepare$qry );
    If ( !
    $req ) {
       Echo 
    "Prepare Issues!";
       die();
    }

    i5_bind_param$req, &$Store );
    $result i5_execute$req );
    if( !
    $result ) {
       Echo 
    "Result Issues!";
       
    i5_close$conn );
       die();
    }

    $row i5_fetch_assoc$req );

    If ( 
    $row ) {

       echo 
    "Store# " .$row['STRNUM']. "<br>";
       echo 
    " Name: " .$row['STRNAM']. "<br>";
       echo 
    "Phone: " .$row['STPHON']. "<br>";

    } Else {

       echo 
    "Found Nothing for Store# $Store <br>";

    }

    Echo 
    "Finished!";

    i5_close$conn ) || print ("FAIL : Failed to disconnect from server :$i5_server_ip");
    ?>
    Looking at the above code... a few notes of things that drove me nuts .. (a short trip, but worth it)

    --The basic flow of Data Retrieval is:
    Assign Query ( $qry above )
    Prepare the Query ( i5_prepare )
    Bind the Parameters *if needed* (i5_bind_param)
    Execute the Query (i5_execute)
    Fetch the data (i5_fetch_assoc)

    ** Side Note ** from past experience, I like the ASSOC better than ARRAY on the Fetch due to the clean look on using what was retrieved. At that point, you can use the $row['VARNAME'] format so it's easier to debug and or maintain down the road. (But, that's just me)


    --Notice the use of Parameters. This allows for building a form, prompting for search criteria and never having to change the QRY statement. They are bound (in order) by the i5_bind_param function. Not a requirement, but does come in handy....

    This is just a start, but it does allow me to start moving in quite a few different directions. Mainly ... the one that *hopefully* pushes my company to use this moving forward!

    PS: Thanks to those websites that help with syntax and flow... too many to list -- but, I have no problems recognizing those who help others!

    Until Next time...

  • #2
    Re: Stage 2 : Getting Connected

    Hiya PHPeeps ... finally got onto a real box.

    This works
    PHP Code:
    $conn1 db2_connect($i5_host$i5_uname$i5_pass); 
    This doesn't
    PHP Code:
    $conn i5_connect($i5_host$i5_uname$i5_pass); 
    V6R1, PHP is working, I can access a file on the IBM i and display it's contents etc via the db2_**** functions. But the i5_**** functions remain a mystery.
    Anyone got any clues as to where to look?

    How do i find out which version of Zend is running (you out there Mike?)

    In all cases (IP_Addr, HostName, 'localhost') connecting with i5_connect fails, but the db2_connect works with the host name.

    This is gonna bug me all weekend. Back again on Monday.

    < e d i t >
    ok so db2_connect connects via a relational database entry.
    How so folks for i5_connect?
    < / e d i t >
    Cheers
    Greg
    Last edited by gcraill; March 27, 2014, 09:29 PM.
    Greg Craill: "Life's hard - Get a helmet !!"

    Comment


    • #3
      Re: Stage 2 : Getting Connected

      Hi there, I'm here! Happy weekend!

      You can determine the current version of Zend Server by looking at the GO LICPGM, option 10. Page down to 2ZSVRPI or 6ZSVRPI to see the version in the title of the LP. You should also get the version of PHP from here as well.

      So the i5_ functions are no longer bundled in Zend Server by default. They are supported by the folks at Aura Equipments via the Easycom plug to PHP. If you are married to these you can reach out to them. Otherwise, you can migrate to the DB2 functions for database access which are supported by IBM and Zend. For RPG, COBOL, CL program calls and other native access you should take a good look at the open source toolkit which is documented at Zend.com and the YiPs website.





      Feel free to contact me directly at mike.p@zend.com.

      Regards,

      Mike












      Originally posted by gcraill View Post
      Hiya PHPeeps ... finally got onto a real box.

      This works
      PHP Code:
      $conn1 db2_connect($i5_host$i5_uname$i5_pass); 
      This doesn't
      PHP Code:
      $conn i5_connect($i5_host$i5_uname$i5_pass); 
      V6R1, PHP is working, I can access a file on the IBM i and display it's contents etc via the db2_**** functions. But the i5_**** functions remain a mystery.
      Anyone got any clues as to where to look?

      How do i find out which version of Zend is running (you out there Mike?)

      In all cases (IP_Addr, HostName, 'localhost') connecting with i5_connect fails, but the db2_connect works with the host name.

      This is gonna bug me all weekend. Back again on Monday.

      < e d i t >
      ok so db2_connect connects via a relational database entry.
      How so folks for i5_connect?
      < / e d i t >
      Cheers
      Greg

      Comment


      • #4
        Re: Stage 2 : Getting Connected

        Thanks Mike,

        FYI - Zend Server for IBM i 5.0.4 ( PHP 5.3 )

        Looking into that toolkit today ...

        Cheers
        Greg
        Greg Craill: "Life's hard - Get a helmet !!"

        Comment

        Working...
        X