48
1 © 2017 Rogue Wave Software, Inc. All Rights Reserved. 1 RPG & DB2 Stored Procedures with PHP

RPG & DB2 Stored Procedures with PHP - Schedschd.ws/hosted_files/commons17/77/Stored Procedures3.0.pdfRPG & DB2 Stored Procedures with PHP ... •Advantages? –Static objects –Indexing,

Embed Size (px)

Citation preview

Page 1: RPG & DB2 Stored Procedures with PHP - Schedschd.ws/hosted_files/commons17/77/Stored Procedures3.0.pdfRPG & DB2 Stored Procedures with PHP ... •Advantages? –Static objects –Indexing,

1© 2017 Rogue Wave Software, Inc. All Rights Reserved. 1

RPG & DB2 Stored Procedures with PHP

Page 2: RPG & DB2 Stored Procedures with PHP - Schedschd.ws/hosted_files/commons17/77/Stored Procedures3.0.pdfRPG & DB2 Stored Procedures with PHP ... •Advantages? –Static objects –Indexing,

2© 2017 Rogue Wave Software, Inc. All Rights Reserved. 2

PHPish Sessions

• Workshop – Make your IBM i Sizzle with Wordpress (Alan)A4AA – 12:30 PM

• Connecting the dots: Building Web Apps w/PHP, HTML & CSS (John)13BH – 10:45 AM

• PHP on IBM i: Getting Started (Mike)14BI – 12:45 PM

• OO and Ahh! Understanding Object Oriented PHP (John)16BI –3:45 PM

• Open Lab: Basic PHP to access your Data on IBM i, Object Oriented PHP (John)21AB – 8:00 AM to Noon

• Introduction to Maria DB for IBM i (Mike)21BJ – 8:00 AM

• PHP and DB2 Essentials (Alan)25BJ – 2:00 PM

• PHP Tricks for the RPG Programmer (Alan & Birgita)25CA – 2:00 PM

• Building Reusable APIs (Stephanie)27BJ – 5:00 PM

• Watson and PHP Inventory Integration (Mike & Clark)32CL – 9:30 AM

• Intro to Python33CL – 11:00 AM

• Using DB2 and SQL with Open Source Languages (Alan & Scott)35CL – 2:00 PM

• IBM i and PHP System Integration (Jim O)35BH – 2:00 PM

• Debugging your web application from A to Zend (Stephanie)41BI – 8:00 AM

• A Real Zend Expressive Application (Clark)42BH – 9:30 AM

• Bring RPG/COBOL Business Logic to the web with PHP Toolkit (Alan)42BI – 9:30 AM

• Object Oriented Business Programming :An intro to DDD (Chuk)46AD – 3:30 PM

• RPG and DB2 Stored procedures with PHP on IBM i (Mike)46BJ – 3:30 PM

• Object Oriented Business Programming :An intro to DDD (Chuk)46CP – 3:30 PM

• Case Study jQuery and PHP – Drag & Drop Scheduling for BPCS (John)46BH – 3:30 PM

• Getting Started with PHP Frameworks (Stephanie)47BH – 5:00 PM

Page 3: RPG & DB2 Stored Procedures with PHP - Schedschd.ws/hosted_files/commons17/77/Stored Procedures3.0.pdfRPG & DB2 Stored Procedures with PHP ... •Advantages? –Static objects –Indexing,

3© 2017 Rogue Wave Software, Inc. All Rights Reserved. 3

Agenda

• DB2

– SQL Stored procedures

– Examples

• RPG

– Hello World from RPG (sp1)

– Pass an array from RPG to PHP (sp2)

– Pass a record set from RPG to PHP (sp3)

• Q&A

Page 4: RPG & DB2 Stored Procedures with PHP - Schedschd.ws/hosted_files/commons17/77/Stored Procedures3.0.pdfRPG & DB2 Stored Procedures with PHP ... •Advantages? –Static objects –Indexing,

4© 2017 Rogue Wave Software, Inc. All Rights Reserved. 4

Introduction to SPs

Page 5: RPG & DB2 Stored Procedures with PHP - Schedschd.ws/hosted_files/commons17/77/Stored Procedures3.0.pdfRPG & DB2 Stored Procedures with PHP ... •Advantages? –Static objects –Indexing,

5© 2017 Rogue Wave Software, Inc. All Rights Reserved. 5

Stored Procedures…What are they?

• Database artifacts that perform a specific task.

• Zend Server PHP on IBM i supports access to multiple DB’s

– DB2

– MySQL

– MS SQL Server

– Oracle

– Mongo DB (Zend Server 5.6)

• Therefore, SP’s on each are available to PHP on IBM i

Page 6: RPG & DB2 Stored Procedures with PHP - Schedschd.ws/hosted_files/commons17/77/Stored Procedures3.0.pdfRPG & DB2 Stored Procedures with PHP ... •Advantages? –Static objects –Indexing,

6© 2017 Rogue Wave Software, Inc. All Rights Reserved. 6

Stored Procedures on IBM i…What are they?

• Operating System Objects but Database attributes

• Typically written in SQL or RPG, but…

• Can be written in nearly any HLL like

– Java, REXX, C, CL, C++, COBOL, FORTRAN, PL1

Page 7: RPG & DB2 Stored Procedures with PHP - Schedschd.ws/hosted_files/commons17/77/Stored Procedures3.0.pdfRPG & DB2 Stored Procedures with PHP ... •Advantages? –Static objects –Indexing,

7© 2017 Rogue Wave Software, Inc. All Rights Reserved. 7

What do they look like?

Simple SP data retrieval:

CREATE PROCEDURE sales_price(

IN Customer# CHAR(8),

IN Product# CHAR(8),

OUT price DECIMAL(12,2))

LANGUAGE SQL

BEGIN

SELECT CustPrice FROM priceTable

WHERE CUSTNO=Customer# AND

PRODNO=Product# AND

active = ‘Y’

END

Page 8: RPG & DB2 Stored Procedures with PHP - Schedschd.ws/hosted_files/commons17/77/Stored Procedures3.0.pdfRPG & DB2 Stored Procedures with PHP ... •Advantages? –Static objects –Indexing,

8© 2017 Rogue Wave Software, Inc. All Rights Reserved. 8

Open Source Toolkit has examples

Page 9: RPG & DB2 Stored Procedures with PHP - Schedschd.ws/hosted_files/commons17/77/Stored Procedures3.0.pdfRPG & DB2 Stored Procedures with PHP ... •Advantages? –Static objects –Indexing,

9© 2017 Rogue Wave Software, Inc. All Rights Reserved. 9

Command line procedure creation

From PASE:

QSH CMD(‘/usr/bin/db2 -t -f

/QSYS.LIB/MPAVLAK.lib/QSQLSRC.FILE/MPSQL1.MBR')

Or…

From Native Command Line

RUNSQLSTM

SRCFILE(MPAVLAK/QSQLSRC) SRCMBR(MPSQL1)

Page 10: RPG & DB2 Stored Procedures with PHP - Schedschd.ws/hosted_files/commons17/77/Stored Procedures3.0.pdfRPG & DB2 Stored Procedures with PHP ... •Advantages? –Static objects –Indexing,

10© 2017 Rogue Wave Software, Inc. All Rights Reserved. 10

IBM i Navigator

Page 11: RPG & DB2 Stored Procedures with PHP - Schedschd.ws/hosted_files/commons17/77/Stored Procedures3.0.pdfRPG & DB2 Stored Procedures with PHP ... •Advantages? –Static objects –Indexing,

11© 2017 Rogue Wave Software, Inc. All Rights Reserved. 11

DB2 Housekeeping

• Supports 2 types

– External (RPG, COBOL, etc.)

– SQL

• Implemented via C programs (transparently)

• Enhancements with each release of IBM i

– Be Careful if developing for multiple OS versions

• SQL details:

– Supports multiple statements

– Supports iterative processing (Loop, Repeat Until, While)

– Get Diagnostics and feedback (SQLSTATE, SQLCODE)

– Can return discrete results or result sets

Page 12: RPG & DB2 Stored Procedures with PHP - Schedschd.ws/hosted_files/commons17/77/Stored Procedures3.0.pdfRPG & DB2 Stored Procedures with PHP ... •Advantages? –Static objects –Indexing,

12© 2017 Rogue Wave Software, Inc. All Rights Reserved. 12

Example

Page 13: RPG & DB2 Stored Procedures with PHP - Schedschd.ws/hosted_files/commons17/77/Stored Procedures3.0.pdfRPG & DB2 Stored Procedures with PHP ... •Advantages? –Static objects –Indexing,

13© 2017 Rogue Wave Software, Inc. All Rights Reserved. 13

Before…

Page 14: RPG & DB2 Stored Procedures with PHP - Schedschd.ws/hosted_files/commons17/77/Stored Procedures3.0.pdfRPG & DB2 Stored Procedures with PHP ... •Advantages? –Static objects –Indexing,

14© 2017 Rogue Wave Software, Inc. All Rights Reserved. 14

Output

Page 15: RPG & DB2 Stored Procedures with PHP - Schedschd.ws/hosted_files/commons17/77/Stored Procedures3.0.pdfRPG & DB2 Stored Procedures with PHP ... •Advantages? –Static objects –Indexing,

15© 2017 Rogue Wave Software, Inc. All Rights Reserved. 15

After

Page 16: RPG & DB2 Stored Procedures with PHP - Schedschd.ws/hosted_files/commons17/77/Stored Procedures3.0.pdfRPG & DB2 Stored Procedures with PHP ... •Advantages? –Static objects –Indexing,

16© 2017 Rogue Wave Software, Inc. All Rights Reserved. 16

Looks the same!

Page 17: RPG & DB2 Stored Procedures with PHP - Schedschd.ws/hosted_files/commons17/77/Stored Procedures3.0.pdfRPG & DB2 Stored Procedures with PHP ... •Advantages? –Static objects –Indexing,

17© 2017 Rogue Wave Software, Inc. All Rights Reserved. 17

And now a word about library lists

Page 18: RPG & DB2 Stored Procedures with PHP - Schedschd.ws/hosted_files/commons17/77/Stored Procedures3.0.pdfRPG & DB2 Stored Procedures with PHP ... •Advantages? –Static objects –Indexing,

18© 2017 Rogue Wave Software, Inc. All Rights Reserved. 18

Option parameter of DB2_Connect

• Options parameter is an array.

• Supports three kinds if library list

– i5_lib – Single library

– i5_naming – Enable library list via user profile

– i5_libl – Specify library list in PHP

• Supports many other parameters

Page 19: RPG & DB2 Stored Procedures with PHP - Schedschd.ws/hosted_files/commons17/77/Stored Procedures3.0.pdfRPG & DB2 Stored Procedures with PHP ... •Advantages? –Static objects –Indexing,

19© 2017 Rogue Wave Software, Inc. All Rights Reserved. 19

Single library approach

• Similar to the world of MySQL/MariaDB.

Page 20: RPG & DB2 Stored Procedures with PHP - Schedschd.ws/hosted_files/commons17/77/Stored Procedures3.0.pdfRPG & DB2 Stored Procedures with PHP ... •Advantages? –Static objects –Indexing,

20© 2017 Rogue Wave Software, Inc. All Rights Reserved. 20

Multiple libraries hardcoded in PHP

• More like real life

Page 21: RPG & DB2 Stored Procedures with PHP - Schedschd.ws/hosted_files/commons17/77/Stored Procedures3.0.pdfRPG & DB2 Stored Procedures with PHP ... •Advantages? –Static objects –Indexing,

21© 2017 Rogue Wave Software, Inc. All Rights Reserved. 21

Job Description – PHPUSER2

• WRKJOBD, DSPJOBD

Page 22: RPG & DB2 Stored Procedures with PHP - Schedschd.ws/hosted_files/commons17/77/Stored Procedures3.0.pdfRPG & DB2 Stored Procedures with PHP ... •Advantages? –Static objects –Indexing,

22© 2017 Rogue Wave Software, Inc. All Rights Reserved. 22

Multiple libraries via User Profile

• Parallels Green Screen access

Page 23: RPG & DB2 Stored Procedures with PHP - Schedschd.ws/hosted_files/commons17/77/Stored Procedures3.0.pdfRPG & DB2 Stored Procedures with PHP ... •Advantages? –Static objects –Indexing,

23© 2017 Rogue Wave Software, Inc. All Rights Reserved. 23

Back to SPs

Page 24: RPG & DB2 Stored Procedures with PHP - Schedschd.ws/hosted_files/commons17/77/Stored Procedures3.0.pdfRPG & DB2 Stored Procedures with PHP ... •Advantages? –Static objects –Indexing,

24© 2017 Rogue Wave Software, Inc. All Rights Reserved. 24

Observations about SPs

• Advantages?

– Static objects

– Indexing, permanent objects

– Manage queries, DBA role is emerging

– Ever heard of little Bobby Tables?

• Disadvantages

– Another thing to manage

Page 25: RPG & DB2 Stored Procedures with PHP - Schedschd.ws/hosted_files/commons17/77/Stored Procedures3.0.pdfRPG & DB2 Stored Procedures with PHP ... •Advantages? –Static objects –Indexing,

25© 2017 Rogue Wave Software, Inc. All Rights Reserved. 25

Security is no laughing matter?

Page 26: RPG & DB2 Stored Procedures with PHP - Schedschd.ws/hosted_files/commons17/77/Stored Procedures3.0.pdfRPG & DB2 Stored Procedures with PHP ... •Advantages? –Static objects –Indexing,

26© 2017 Rogue Wave Software, Inc. All Rights Reserved. 26

Understand which Exec to use

• DB2_Exec

– Fire and forget

– Use when no parameters necessary

• DB2_Execute

– Prepared SQL via DB2_Prepare & DB2 bind

– Always use when using parameters

– Example in Samples

Page 27: RPG & DB2 Stored Procedures with PHP - Schedschd.ws/hosted_files/commons17/77/Stored Procedures3.0.pdfRPG & DB2 Stored Procedures with PHP ... •Advantages? –Static objects –Indexing,

27© 2017 Rogue Wave Software, Inc. All Rights Reserved. 27

Hello World

Page 28: RPG & DB2 Stored Procedures with PHP - Schedschd.ws/hosted_files/commons17/77/Stored Procedures3.0.pdfRPG & DB2 Stored Procedures with PHP ... •Advantages? –Static objects –Indexing,

28© 2017 Rogue Wave Software, Inc. All Rights Reserved. 28

Start slow

• Don’t try to boil the ocean with your first SP!

• How did you learn RPG?

– Reports

– Batch

– Interactive

– Subfiles, etc…

• Start with simple SP’s and grow..

Page 29: RPG & DB2 Stored Procedures with PHP - Schedschd.ws/hosted_files/commons17/77/Stored Procedures3.0.pdfRPG & DB2 Stored Procedures with PHP ... •Advantages? –Static objects –Indexing,

29© 2017 Rogue Wave Software, Inc. All Rights Reserved. 29

An approach

• Process:

– Create RPG

– Identify parameter interface

– Create procedure

– Test in Database Navigator

– Try it in PHP

– Increase complexity a little

– Repeat!

Page 30: RPG & DB2 Stored Procedures with PHP - Schedschd.ws/hosted_files/commons17/77/Stored Procedures3.0.pdfRPG & DB2 Stored Procedures with PHP ... •Advantages? –Static objects –Indexing,

30© 2017 Rogue Wave Software, Inc. All Rights Reserved. 30

RPG

Page 31: RPG & DB2 Stored Procedures with PHP - Schedschd.ws/hosted_files/commons17/77/Stored Procedures3.0.pdfRPG & DB2 Stored Procedures with PHP ... •Advantages? –Static objects –Indexing,

31© 2017 Rogue Wave Software, Inc. All Rights Reserved. 31

Create the procedure & test

CREATE PROCEDURE MPAVLAK/RPGSP1(INOUT Response CHAR ( 32)) LANGUAGE RPGLE

NOT DETERMINISTIC CONTAINS SQL EXTERNAL NAME MPAVLAK/RPGSP1 PARAMETER STYLE GENERAL

Then fire up System i Navigator

Page 32: RPG & DB2 Stored Procedures with PHP - Schedschd.ws/hosted_files/commons17/77/Stored Procedures3.0.pdfRPG & DB2 Stored Procedures with PHP ... •Advantages? –Static objects –Indexing,

32© 2017 Rogue Wave Software, Inc. All Rights Reserved. 32

Admire results in DB Nav

Page 33: RPG & DB2 Stored Procedures with PHP - Schedschd.ws/hosted_files/commons17/77/Stored Procedures3.0.pdfRPG & DB2 Stored Procedures with PHP ... •Advantages? –Static objects –Indexing,

33© 2017 Rogue Wave Software, Inc. All Rights Reserved. 33

Now try it in PHP

Page 34: RPG & DB2 Stored Procedures with PHP - Schedschd.ws/hosted_files/commons17/77/Stored Procedures3.0.pdfRPG & DB2 Stored Procedures with PHP ... •Advantages? –Static objects –Indexing,

34© 2017 Rogue Wave Software, Inc. All Rights Reserved. 34

Results from Script

Page 35: RPG & DB2 Stored Procedures with PHP - Schedschd.ws/hosted_files/commons17/77/Stored Procedures3.0.pdfRPG & DB2 Stored Procedures with PHP ... •Advantages? –Static objects –Indexing,

35© 2017 Rogue Wave Software, Inc. All Rights Reserved. 35

Array from RPG to PHP

Page 36: RPG & DB2 Stored Procedures with PHP - Schedschd.ws/hosted_files/commons17/77/Stored Procedures3.0.pdfRPG & DB2 Stored Procedures with PHP ... •Advantages? –Static objects –Indexing,

36© 2017 Rogue Wave Software, Inc. All Rights Reserved. 36

Now an array

• Data elements are nice, but…

• Sometimes you need a little more…

• How about an array of information?

Page 37: RPG & DB2 Stored Procedures with PHP - Schedschd.ws/hosted_files/commons17/77/Stored Procedures3.0.pdfRPG & DB2 Stored Procedures with PHP ... •Advantages? –Static objects –Indexing,

37© 2017 Rogue Wave Software, Inc. All Rights Reserved. 37

SQL to create the SP & test in iNav

CREATE PROCEDURE mpavlak/rpgsp2() LANGUAGE RPGLE

EXTERNAL NAME mpavlak/rpgsp2 GENERAL

Page 38: RPG & DB2 Stored Procedures with PHP - Schedschd.ws/hosted_files/commons17/77/Stored Procedures3.0.pdfRPG & DB2 Stored Procedures with PHP ... •Advantages? –Static objects –Indexing,

38© 2017 Rogue Wave Software, Inc. All Rights Reserved. 38

Open results in PHP

Page 39: RPG & DB2 Stored Procedures with PHP - Schedschd.ws/hosted_files/commons17/77/Stored Procedures3.0.pdfRPG & DB2 Stored Procedures with PHP ... •Advantages? –Static objects –Indexing,

39© 2017 Rogue Wave Software, Inc. All Rights Reserved. 39

Results in browser

Page 40: RPG & DB2 Stored Procedures with PHP - Schedschd.ws/hosted_files/commons17/77/Stored Procedures3.0.pdfRPG & DB2 Stored Procedures with PHP ... •Advantages? –Static objects –Indexing,

40© 2017 Rogue Wave Software, Inc. All Rights Reserved. 40

Record set from RPG

Page 41: RPG & DB2 Stored Procedures with PHP - Schedschd.ws/hosted_files/commons17/77/Stored Procedures3.0.pdfRPG & DB2 Stored Procedures with PHP ... •Advantages? –Static objects –Indexing,

41© 2017 Rogue Wave Software, Inc. All Rights Reserved. 41

Have RPG build the result set and use SQL…

Page 42: RPG & DB2 Stored Procedures with PHP - Schedschd.ws/hosted_files/commons17/77/Stored Procedures3.0.pdfRPG & DB2 Stored Procedures with PHP ... •Advantages? –Static objects –Indexing,

42© 2017 Rogue Wave Software, Inc. All Rights Reserved. 42

SQL to create the SP & test in iNav

CREATE PROCEDURE mpavlak/rpgsp3() LANGUAGE RPGLE

EXTERNAL NAME mpavlak/rpgsp3 GENERAL

Page 43: RPG & DB2 Stored Procedures with PHP - Schedschd.ws/hosted_files/commons17/77/Stored Procedures3.0.pdfRPG & DB2 Stored Procedures with PHP ... •Advantages? –Static objects –Indexing,

43© 2017 Rogue Wave Software, Inc. All Rights Reserved. 43

Now open results in PHP

Page 44: RPG & DB2 Stored Procedures with PHP - Schedschd.ws/hosted_files/commons17/77/Stored Procedures3.0.pdfRPG & DB2 Stored Procedures with PHP ... •Advantages? –Static objects –Indexing,

44© 2017 Rogue Wave Software, Inc. All Rights Reserved. 44

Now open results in browser

Page 45: RPG & DB2 Stored Procedures with PHP - Schedschd.ws/hosted_files/commons17/77/Stored Procedures3.0.pdfRPG & DB2 Stored Procedures with PHP ... •Advantages? –Static objects –Indexing,

45© 2017 Rogue Wave Software, Inc. All Rights Reserved. 45

Wrap it up…

Page 46: RPG & DB2 Stored Procedures with PHP - Schedschd.ws/hosted_files/commons17/77/Stored Procedures3.0.pdfRPG & DB2 Stored Procedures with PHP ... •Advantages? –Static objects –Indexing,

46© 2017 Rogue Wave Software, Inc. All Rights Reserved. 46

Q&A

• Mike Pavlak – [email protected]

Page 47: RPG & DB2 Stored Procedures with PHP - Schedschd.ws/hosted_files/commons17/77/Stored Procedures3.0.pdfRPG & DB2 Stored Procedures with PHP ... •Advantages? –Static objects –Indexing,

47© 2017 Rogue Wave Software, Inc. All Rights Reserved. 47

ATTENDConnect with experts.Become an authority.Register now:zendcon.com/register-now

EXPLOREShare, inspire, educate.Network

SPONSORSpotlight your best in enterprise PHP, opensource & frameworks:[email protected]

Visit zendcon.com

Page 48: RPG & DB2 Stored Procedures with PHP - Schedschd.ws/hosted_files/commons17/77/Stored Procedures3.0.pdfRPG & DB2 Stored Procedures with PHP ... •Advantages? –Static objects –Indexing,

48© 2017 Rogue Wave Software, Inc. All Rights Reserved. 48