Bringing i5/OS Resources to the Web
January 16, 2008 Erwin Earley
This is the fourth article in a PHP on i5/OS series and it continues our discussion of the API toolkit included with the Zend Core product. In my previous article Use PHP to Bring i5/OS Resources to the Web, I explained that the API toolkit is a collection of APIs for accessing i5/OS resources from PHP applications. The Zend Core product splits functions for accessing i5/OS resources into two broad categories: a collection of functions for accessing db2 resources, and a collection of functions for accessing all other i5/OS resources. The following diagram provides an overview of the structure of those i5/OS resource functions: Observe in the above diagram that the functions in the i5 Toolkit allow for accessing native i5/OS resources only on the local system (i.e., resources in the same i5/OS partition where Zend Core is installed), while the db2 functions allow for accessing of db2 related resources (via SQL support) on the local as well as remote systems. The db2 related functions are an extension to the PHP language and the function names all begin with the characters “db2_”. The db2 functions will be discussed in my next article. The toolkit functions are contained in the API toolkit and begin with the characters “i5_”. This article completes our discussion of the API toolkit functions. Record-Level Access The API toolkit includes functions for accessing records from physical files. Functions in this category include the following:
Let’s take a look at a code snippet that uses these record-level access functions. Note: The code in the above graphic is available for download here. A couple of general notes for this code snippet are needed before we look into its specific aspects. To begin with this is not a complete code sample–the complete code would include the PHP tags and the function calls to connect to i5/OS. Additionally, this code would have been invoked from an HTML form that would have been used to supply the file and library name. Now, let’s dive deeper into aspects of this code sample:
Following is an example of the output that can be generated by the above code: Program Call PHP programs in i5/OS are able to invoke programs in the Integrated Language Environment (ILE), send parameters to those programs, and get results from those programs. The following functions are included in the Program Call group of APIs:
For this example we need to look at the program to be called as well the PHP code. Let’s first take a look at the CL program to be called: PGM PARM(&SOMESTRING &SOMENUM) DCL VAR(&SOMESTRING) TYPE(*CHAR) LEN(10) DCL VAR(&SOMENUM) TYPE(DEC) LEN(15 5) CHGVAR VAR(&SOMESTRING) VALUE(%SST(&SOMESTRING 1 3)) CHGVAR VAR(&SOMENUM) VALUE(&SOMENUM + 1) ENDPGM As you can see the program takes two arguments: a string (referred to as SOMESTRING), and a number (referred to as SOMENUM). The program will return the first three characters of the input string and the number that was input incremented by one. Now let’s take a look at the PHP code: Note: The code in the above graphic is available for download here. Like our previous example, this is an incomplete PHP code sample, as it is missing items such as the PHP tags. Additionally the code is making use of form values that would have been supplied by a corresponding HTML form. Now let’s look deeper into this code:
Array ( [0] => Array ( [name] => SOMESTRING [IO] => I5_INOUT [Type] => I5_TYPE_CHAR [Length] => 10 ) [1] => Array ( [name] => SOMENUM [IO] => I5_INOUT [Type] => i5_TYPE_PACKED [Length] => 15.5 ) )
Working with Data Areas Let’s take a look at one more code sample for the i5 toolkit APIs. This example will show how you can work with data areas from PHP programs. We’ll start with a code sample: Note: The code in the above graphic is available for download here.
Conclusion I hope you have gained some insight and benefit from this look into the functions and capabilities provided by the i5 API toolkit that is provided with the Zend Core product. The next article in this series will take a look at the db2 extensions that Zend has provided for the PHP language. Erwin Earley is an advisory software engineer in the IBM lab located in Rochester, Minnesota, and heads up the Open Source Technologies Center of Competency for System i within the System i Technology Center. At that center, he provides education and enablement services for open source related technologies on System i including Linux, MySQL, and Zend’s PHP. Earley currently holds certifications from Red Hat as well as the Linux Professional Institute and is a candidate for certification with Zend’s PHP. RELATED STORIES Use PHP to Bring i5/OS Resources to the Web PHP: An Easy Yet Powerful Language Syntax PHP on i5/OS: A Whole New Stack
|