PHP on IBM i RPG Examples

Mike Pavlak Solution Consultant Mike.p@.com

© All rights reserved. Zend Technologies, Inc. Agenda

•Open Source Toolkit •RPG Program Calls •Stored Procedures •Q&A

2 © All rights reserved. Zend Technologies, Inc. Zend Server 7 for IBM i

Key Features Z-Ray (Like Firebug for PHP) Server Dashboards Code libraries Much more!

3 © All rights reserved. Zend Technologies, Inc. RPG Examples www.zend.com

Introduction to PHP

© All rights reserved. Zend Technologies, Inc. PHP is a Scripting Language PHP Hypertext Pre-Processor Developed initially by in 1994: PHP/FI Zeev Suraski and Contributing since1997+ (ZEev + aNDi = Zend) Interpreted, not compiled Forgiving and intuitive code structure (Short learning curve) Immediate feedback during development PHP is to Java what RPG is to COBOL

| 5 Geting Started with PHP on IBM i © All rights reserved. Zend Technologies, Inc. What Is Zend Server?

• Production quality PHP stack  PHP, ZF, DB connectivity, debugging extension, and more • Three Editions – No charge “Basic Edition” provided by IBM & Full Professional and Enterprise commercial edition  All are production ready • Application monitoring and diagnostics (integrated with ) • Multi-level performance enhancement capabilities • Software updates and security hot fixes • Easy and quick installation • Zend Framework Integration

| 6 Geting Started with PHP on IBM i © All rights reserved. Zend Technologies, Inc. Zend Server Under the Covers IBM i

ILE Apache:10080 i/OS • Default PHP file configuration PASE FastCGI HTTP:10080 Apache URL Request PHP CGI *PGM Server

(FastCGI) CMD HTML/response

Zend Server DB2 UDB

MySQL, SQL Server,

| 7 Geting Started with PHP on IBM i © All rights reserved. Zend Technologies, Inc. Oracle Sample Scripts! (http://IBMi:10080/samples )

| 8 Geting Started with PHP on IBM i © All rights reserved. Zend Technologies, Inc. | 9| Geting Started with PHP on IBM i © All rights reserved. Zend Technologies, Inc. Sample Script – Hello World • Obligatory program when starting out • Confirms correct setup of PHP • Sample code: (Shortest PHP Macro around!) • Save script in IFS /www/zendsvr6/htdocs /helloworld. • Browser URL: http://ibmisystem:10080/helloworld.php

| Geting Started with PHP on IBM i © All rights reserved. Zend Technologies, Inc. 10 | Geting Started with PHP on IBM i © All rights reserved. Zend Technologies, Inc. 11 Basic file listing script (Update) • Connect to DB2 i • Select records from a DB2 table • Load the records in an HTML table

| Geting Started with PHP on IBM i © All rights reserved. Zend Technologies, Inc. 12 02/03 /10 Connection to DB2 for i (Update) • Need three things:  System Note: If your data sets have *PUBLIC  User ID access, no user or password is required  Password

| Geting Started with PHP on IBM i © All rights reserved. Zend Technologies, Inc. 13 02/03 /10 Reading data...(Update) Loop through record set

| Geting Started with PHP on IBM i © All rights reserved. Zend Technologies, Inc. 14 02/03 /10 Basic file listing script (Update)

| Geting Started with PHP on IBM i © All rights reserved. Zend Technologies, Inc. 15 02/03 /10 RPG Examples www.zend.com

Open Source Toolkit

© All rights reserved. Zend Technologies, Inc. What is the toolkit?

•Set of classes that access IBM i native artifacts •All Program Objects RPG, COBOL, CL, etc. •Others Command processor Data Queue’s Spooled File More… •Access naturally from PHP code. No SP’s required •Easy to use

17 Insert->Header & Footer © All rights reserved. Zend Technologies, Inc. New toolkit is Object Oriented

•Series of classes that “wrap” the IBM project •All PHP but Object Oriented…(wait, there’s more!) •Zend built the PHP wrapper •No OO training required to use them!!!

•Sam Pinkhasov, Zend

19 Insert->Header & Footer © All rights reserved. Zend Technologies, Inc.

XML Service

•IBM has open sourced XMLService. •First Open Source project on IBM i. (that I know of…) •Made up of RPG, CL and DB2 stored procedures (SQL)

•Tony Cairns, IBM Rochester

21 Insert->Header & Footer © All rights reserved. Zend Technologies, Inc. XML Service

•Cross platform •Language agnostic •Basic plumbing for all open source languages

22 Insert->Header & Footer © All rights reserved. Zend Technologies, Inc. Compatibility Wrapper

•Intercepts existing i5 function requests •Written in pure PHP •Passes them on to OO PHP which then… •Passes on to XML Service

•Alan Seiden, SBS & alanseiden.com

23 Insert->Header & Footer © All rights reserved. Zend Technologies, Inc. Source Code for XML Service on YiPs…

•http://youngiprofessionals.com/

24 Insert->Header & Footer © All rights reserved. Zend Technologies, Inc. Source Code for PHP Toolkit on GitHub…

•https://github.com/zendtech/IbmiToolkit

25 Insert->Header & Footer © All rights reserved. Zend Technologies, Inc. PHP Classes

•Class where all wrapper functions start Yes, this is OO but not too bad… Look at it and poke around, It’s OK! This is why we need the path set correctly

26 Insert->Header & Footer © All rights reserved. Zend Technologies, Inc. Housekeeping…

•Need to set the extension and instantiate the object Singleton pattern Try & Catch Can put this in your own include

27 Insert->Header & Footer © All rights reserved. Zend Technologies, Inc. Now the program call

•Set parameters based on function Call program V I C L a n o e r i I m  n t Output results m / g e n t v n a O h a t m e l

28 Insert->Header & Footer © All rights reserved. Zend Technologies, Inc. AddParameterChar •Located in ToolkitService.php /usr/local/zendsvr/share/ToolkitAPI Uses CharParam which extends ProgramParam, etc…

29 Insert->Header & Footer © All rights reserved. Zend Technologies, Inc. Before and after…Part 1 •Existing code call

30 Insert->Header & Footer © All rights reserved. Zend Technologies, Inc. Before and after…Part 2 •New Open Source Toolkit program call

31 Insert->Header & Footer © All rights reserved. Zend Technologies, Inc. Additional Parameter Types

• AddParameterInt32($io, $comment, $varName, $value, $dimension) • AddParameterInt64($io, $comment, $varName, $value, $dimension) • AddParameterUInt32($io, $comment, $varName, $value, $dimension) • AddParameterUInt64($io, $comment, $varName, $value, $dimension) • AddParameterFloat ($io, $comment, $varName, $value, $dimension) • AddParameterReal($io, $comment, $varName, $value, $dimension) • AddParameterPackdec($io, $length, $scale, $comment, $varName, $value, $dimension) • AddParameterZoned($io, $length, $scale, $comment, $varName, $value, $dimension) • AddParameterBin($io, $size, $comment, $varName, $value, $dimension) • AddDataStruct($array, $parameters, $name=‘struct_name’, $dim, $by, $isArray, $labelLen)

32 Insert->Header & Footer © All rights reserved. Zend Technologies, Inc.

RPG Examples www.zend.com

Stored Procedure - Array

© All rights reserved. Zend Technologies, Inc. Now an array

Data elements are nice, but… Sometimes you need a little more… How about an array of information?

34 © All rights reserved. Zend Technologies, Inc. Have RPG build an array and use SQL…

35 Insert->Header & Footer © All rights reserved. Zend Technologies, Inc. SQL to create the SP & test in iNav CREATE PROCEDURE mpavlak/rpgsp2() LANGUAGE RPGLE EXTERNAL NAME mpavlak/rpgsp2 GENERAL

36 Insert->Header & Footer © All rights reserved. Zend Technologies, Inc. Test it in iNav…

37 Insert->Header & Footer © All rights reserved. Zend Technologies, Inc. Now open results in PHP…

38 Insert->Header & Footer © All rights reserved. Zend Technologies, Inc. Results in browser…

39 Insert->Header & Footer © All rights reserved. Zend Technologies, Inc. RPG Examples www.zend.com

Stored Procedure – Record Set

© All rights reserved. Zend Technologies, Inc. Have RPG build the result set and use SQL…

41 Insert->Header & Footer © All rights reserved. Zend Technologies, Inc. SQL to create the SP & test in iNav CREATE PROCEDURE mpavlak/rpgsp3() LANGUAGE RPGLE EXTERNAL NAME mpavlak/rpgsp3 GENERAL

42 Insert->Header & Footer © All rights reserved. Zend Technologies, Inc. Now open results in PHP…

43 Insert->Header & Footer © All rights reserved. Zend Technologies, Inc. Results in browser…

44 Insert->Header & Footer © All rights reserved. Zend Technologies, Inc. Zend Server Update www.zend.com

Command processing & *libl

© All rights reserved. Zend Technologies, Inc. Several ways to call commands…

•$conn->CLCommand(‘my command’); •$conn->CLInteractiveCommand(‘DSP… command’); •$conn->CLCommandWithOutput(‘RTV… command’);

© All rights reserved. Zend Technologies, Inc. Other uses for the toolkit

•Command processing Call CL command directly from toolkit Retrieve response from command call •Example DSPLIBL CHGLIBL DSPLIBL Useful for managing access to resource • Files & Programs from RPG

47 Insert->Header & Footer © All rights reserved. Zend Technologies, Inc. 48 Insert->Header & Footer © All rights reserved. Zend Technologies, Inc. PHP Code

49 Insert->Header & Footer © All rights reserved. Zend Technologies, Inc. 50 Insert->Header & Footer © All rights reserved. Zend Technologies, Inc. Zend Server Update www.zend.com

Pricing Example

© All rights reserved. Zend Technologies, Inc. Standard line discount

•RPG is black box, callable from nearly anywhere •PHP has function to contain RPG call •Routine to spin through line call for each quantity

52 Insert->Header & Footer © All rights reserved. Zend Technologies, Inc. Mainline of code

53 Insert->Header & Footer © All rights reserved. Zend Technologies, Inc. CalcDiscount() Part 1

•Setup session for user-RPG program dedication

54 Insert->Header & Footer © All rights reserved. Zend Technologies, Inc. CalcDiscount() Part 2 •Create object, etc.

55 Insert->Header & Footer © All rights reserved. Zend Technologies, Inc. CalcDiscount() Part 3 •Call program

56 Insert->Header & Footer © All rights reserved. Zend Technologies, Inc. Zend Server Update www.zend.com

Miscellaneous Toolkit Points

© All rights reserved. Zend Technologies, Inc. What was passed?

•Toolkit.ini setting Debug = TRUE •Turns on DebugOutput file debugLogFile = "/usr/local/zendsvr/share/ToolkitApi/debug.log“ •Many other directive settings here

58 Insert->Header & Footer © All rights reserved. Zend Technologies, Inc. Contents of output

59 Insert->Header & Footer © All rights reserved. Zend Technologies, Inc. Stateful processing

•IPC •Use session ID, for example • $PHPToolkitObj->setToolkitServiceParams ( array ('InternalKey' => "/tmp/$user" ) );

60 Insert->Header & Footer © All rights reserved. Zend Technologies, Inc. Zend Server Update www.zend.com

Wrap it up

© All rights reserved. Zend Technologies, Inc. Join us at ZendCon Advancing the World of PHP

Conference Tracks Conference Highlights

● PHP Best Practices & Tooling ● Sessions designed for all knowledge levels Take home the latest tips and techniques for high-quality ● Intensive tutorials for accelerated learning PHP apps ● UnConference sessions for expanded topics ● Continuous Delivery & DevOps ● PHP Certification crash course and 50% discount on Explore best practices for high-velocity application certification exams delivery ● Exhibit hall showcasing the latest products ● Application Architecture - APIs, Mobile, ● Networking opportunities with PHP community Cloud Services members and thought-leaders from around the Learn how to harness the server-side and client-side world revolutions

© All rightswww.zendcon.com reserved. Zend Technologies, Inc. Q&A

www.zend.com

[email protected]

Please fill out your Session Evaluation!

63 Insert->Header & Footer © All rights reserved. Zend Technologies, Inc.