Using procedures and service programs with the PHP Toolkit for IBM i

The open source PHP Toolkit enables PHP applications to call procedures (functions) that are defined within RPG service programs on IBM i. (For more information on the toolkit, see my toolkit information page.)

Here’s an example that will work with PHP Toolkit API version 1.4.0 or higher. I also included some ‘boilerplate’ to show best practices for connecting to the toolkit and checking for a successful connection. The illustration of how to call a procedure is in the second half.


// connect to toolkit using DB2 credentials (can also leave blank for default authority)
try {
    $conn = ToolkitService::getInstance('*LOCAL', 'MYUSER', 'MYPASS');
} catch (Exception $e) {
    // Determine reason for failure.
    // Probably database authentication error or invalid or unreachable database.
    $code = $e->getCode();
    $msg = $e->getMessage();

    switch ($code) {
        case 8001:
            // "Authorization failure on distributed database connection attempt"
            // Usually means a wrong DB2 user or password
            echo 'Could not connect due to wrong user or password.';
        case 42705:
            echo 'Database not found. Try WRKRDBDIRE to check.';
            echo 'Could not connect. Error: ' . $code . ' ' . $msg;
    } //(switch)
    die; // couldn't connect...handle this however you wish     
} //(try/catch)

// set stateless mode for easy testing (no 'InternalKey' needed).
// (setOptions() introduced in v1.4.0)

/* If you wish to test this script but you don't have a real service program,
 * use parseOnly and parseDebugLevel as shown below.
 * No program will be called and you'll get your original values back.
 * Simply uncomment the next line to try this great testing feature of the toolkit.
//$conn->setOptions(array('parseOnly'=>true, 'parseDebugLevel'=>1));

// define several input/output params
$params[] = $conn->AddParameterChar('in', 1,'Division', 'DIV', 'A');
$params[] = $conn->AddParameterChar('in', 6,'Product', 'PROD', '123456');
$params[] = $conn->AddParameterPackDec('both', 7, 2, 'Quantity', 'QTY', '4.53');
$params[] = $conn->AddParameterZoned('out', 5, 2, 'Price', 'PRICE', '0');

// define a procedure return param. Can be any type, even a data structure
$retParam = $conn->AddParameterInt32('out', '4-byte int', 'MYRESULT', '13579');

/* Call service program procedure. 
 * In this example, assume your program is MYLIB/MYPGM and has a procedure/function 'myproc'
 * (procedure name is case-sensitive).
 * Note: specify optional procedure name in parameter 5, an array with associative index 'func'.
$result = $conn->PgmCall('MYPGM', 'MYLIB', $params, $retParam, array('func'=>'myproc'));

if (!$result) {
    echo 'Error calling program. Code: ' . $conn->getErrorCode() . ' Msg: ' . $conn->getErrorMsg();

echo 'Called program successfully.<BR><BR>';
echo 'Input/output params: QTY: ' . $result['io_param']['QTY'] . ' PRICE: ' . $result['io_param']['PRICE'] . '<BR>'; 
echo 'Procedure return param MYRESULT: ' . $result['retvals']['MYRESULT']; 

The above will output something like:

Called program successfully.

Input/output params: QTY: 4.53 PRICE: 0.00
Procedure return param MYRESULT: 13579

This entry was posted in IBM i, iSeries, PHP, System i, Zend Server, Zend's PHP toolkit for IBM i. Bookmark the permalink.

10 Responses to Using procedures and service programs with the PHP Toolkit for IBM i

  1. webpage says:

    Write more, thats all I have to say. Literally, it seems as though you relied on the video
    to make your point. You clearly know what youre talking about, why
    throw away your intelligence on just posting videos to your blog when you could
    be giving us something enlightening to read?

  2. When the electricity is passed a friction is created and thereby heat.
    Quite a few solo mess devices may, even so, be taken meant for combining.
    Extruders may be divided into three general types :

  3. This won’t HURT your results such as the above methods-but it certainly can’t enable them to either.

    Drink plenty of water all day- 6-8 associated with
    water can help detoxify the body. Do not turn on the television and sink into
    the couch right after dinner.

  4. christine says:

    Βecаuse the unemplоуmеnt pace continues аbig
    t a higher leѵеd, even іdeborah
    spite оp oker an improvement inside the labог market, your Feԁ
    is сontinuіonal to do what you can to further improve the financial
    state yоuг clients’ nеeԁs high career lеvels and constant prices If you satisfy all
    these some criterions, then you are truly permitted apply for our own short term

  5. Yet, nothing you’ve seen prior, were there a lot of experts or products available to assist us to lose weight.
    It’s essential are tracking how many calories you take in on a daily basis because that will make an extremely large difference in how
    quickly it is possible to have a flat stomach. It will require around 7-10 days to accomplish a cleanse and results can start being noticed inside the
    first three days.

  6. I really love your blog.. Excellent colors & theme. Did you develop this site yourself?

    Please reply back as I’m attempting to create my very own blog and want to learn where you got this from or exactly
    what the theme is named. Many thanks!

  7. Every weekend i used to pay a quick visit
    this web page, as i wish for enjoyment, since this this site conations really nice funny information too.

  8. Some of them are just a sheer waste of time and
    embarrassment to the developers. The particular cell phone
    you use will identify if it is compatible together with your
    preferred software program. Or you could judge a game’s success based solely off of its commercial success.

  9. Activate the alert to view specifics of your nearby match and
    when you find the profile suitable, get up to date in seconds.
    There are sites that will charge a fee on your membership and also the
    privilege that comes with it. If you’ve not, begin using the Ad
    – Words platform of Google now.

  10. The members are the organizations and firms approved by the Board, that have a public pricelist in Belgium for supplying the
    Web services or relevant IP services.

  11. With havin so much content and articles do you ever run into any problems of plagorism or
    copyright violation? My blog has a lot of exclusive content I’ve
    either authored myself or outsourced but it looks
    like a lot of it is popping it up all over the web without my authorization. Do you
    know any ways to help stop content from being ripped off?
    I’d really appreciate it.

  12. AbeBrileygi says:

    I see, that your blog needs fresh & unique content. I know it’s
    hard to write content manually everyday, but there is solution for this.
    Simply search in google for: Imcad’s Essential Tool

  13. I visited many websites except the audio quality for audio songs current
    at this website is actually fabulous.

  14. Hey just wanted to give you a quick heads up. The words in your article
    seem to be running off the screen in Firefox.
    I’m not sure if this is a formatting issue or something to
    do with internet browser compatibility but I figured
    I’d post to let you know. The layout look great though!
    Hope you get the problem fixed soon. Thanks

  15. When you start that and the other party makes a purchase, you receive
    a free or commission for your referral. If they have any support issue,
    the vendor is responsible for that. Keep in mind that there
    are thousands of others trying to make money this way,
    and only a small percentage actually experiences any amount of successful affiliate marketing.

  16. Wonderful goods from you, man. I’ve understand your stuff previous
    to and you are just extremely great. I really
    like what you have acquired here, really like what
    you are saying and the way in which you say it.
    You make it enjoyable and you still care for to keep it smart.
    I cant wait to read far more from you. This is actually a
    terrific website.

  17. When I originally left a comment I seem to have clicked the -Notify me when new comments are added- checkbox and now whenever a comment
    is added I receive four emails with the same comment. Is there
    an easy method you can remove me from that service?
    Thanks a lot!

  18. Www.1Cbit.Ua says:

    Ridiculous story there. What occurred after? Thanks!

  19. anal bondage says:

    free animal sex pics

  20. Remember you’ll be exercising your legs, hips, calves as well as your back,
    so to avoid damaging these parts of your body you’ll need to ensure you warm to boost the blood
    flow about bat roosting parts of one’s body. Rule #1 when attempting to select a vertical
    training program is always to not give so much importance
    about how fancy your website looks. Workouts are varied over the week which means you do not get bored or peak too early.

Leave a Reply

Your email address will not be published. Required fields are marked *