db2 data access with php on ibm i - tug · db2 data access with php on ibm i ... ■can connect to...

46
Db2 Data Access with PHP on IBM i Mike Pavlak – IT Strategist [email protected]

Upload: others

Post on 13-May-2020

25 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Db2 Data Access with PHP on IBM i - TUG · Db2 Data Access with PHP on IBM i ... ■Can connect to remote IBM i for no extra charge. DB2 & PHP: Improvements. 9 You must be able to

Db2 Data Access with PHP on IBM i

Mike Pavlak – IT Strategist

[email protected]

Page 2: Db2 Data Access with PHP on IBM i - TUG · Db2 Data Access with PHP on IBM i ... ■Can connect to remote IBM i for no extra charge. DB2 & PHP: Improvements. 9 You must be able to

2

Agenda

■ Fundamentals

■ DB2 Improvements

■ Default Connection

■ PHP options for *LIBL

■ ibm_db2.ini

■ Column Heading

■ Featured Functions

■ Data Cache in action

Page 3: Db2 Data Access with PHP on IBM i - TUG · Db2 Data Access with PHP on IBM i ... ■Can connect to remote IBM i for no extra charge. DB2 & PHP: Improvements. 9 You must be able to

DB2 & PHP: Fundamentals

Page 4: Db2 Data Access with PHP on IBM i - TUG · Db2 Data Access with PHP on IBM i ... ■Can connect to remote IBM i for no extra charge. DB2 & PHP: Improvements. 9 You must be able to

4

php.net

■ http://php.net/manual/en/book.ibm-db2.php

Page 5: Db2 Data Access with PHP on IBM i - TUG · Db2 Data Access with PHP on IBM i ... ■Can connect to remote IBM i for no extra charge. DB2 & PHP: Improvements. 9 You must be able to

5

php.net

■ Home base of all functions

▶Descriptions

▶Examples

▶Notes

■ All functions

■ All options

Page 6: Db2 Data Access with PHP on IBM i - TUG · Db2 Data Access with PHP on IBM i ... ■Can connect to remote IBM i for no extra charge. DB2 & PHP: Improvements. 9 You must be able to

6

YoungiProfessionals.com

■ DB2 Connections:

■ http://yips.idevcloud.com/wiki/index.php/PHP/DB2Documents

Page 7: Db2 Data Access with PHP on IBM i - TUG · Db2 Data Access with PHP on IBM i ... ■Can connect to remote IBM i for no extra charge. DB2 & PHP: Improvements. 9 You must be able to

7

What’s the name of your database?

■ Helpful in iASP situation and best practice

■ Probably your system name but not necessarily, can be changed HOT

■ Can connect to remote IBM i for no extra charge

Page 8: Db2 Data Access with PHP on IBM i - TUG · Db2 Data Access with PHP on IBM i ... ■Can connect to remote IBM i for no extra charge. DB2 & PHP: Improvements. 9 You must be able to

DB2 & PHP: Improvements

Page 9: Db2 Data Access with PHP on IBM i - TUG · Db2 Data Access with PHP on IBM i ... ■Can connect to remote IBM i for no extra charge. DB2 & PHP: Improvements. 9 You must be able to

9

You must be able to answer these

■ What version of the Operating System are we running?

■ What technology Refresh is installed?

■ DSPPTF

■ WRKPTFGRP

■ Pres F11

Page 10: Db2 Data Access with PHP on IBM i - TUG · Db2 Data Access with PHP on IBM i ... ■Can connect to remote IBM i for no extra charge. DB2 & PHP: Improvements. 9 You must be able to

10

V5R4

■ Automatic Index Advisor

■ Plan cache

■ Show Indexes and MQT

■ RANK(), ROW_NUMBER(), LIKE, LOB,

■ Recursion

■ 2MB SQL Statements

■ Free format RPG & SQL

Page 11: Db2 Data Access with PHP on IBM i - TUG · Db2 Data Access with PHP on IBM i ... ■Can connect to remote IBM i for no extra charge. DB2 & PHP: Improvements. 9 You must be able to

11

i6.1

■ VALUES in from clause

■ FETCH FIRST and ORDR BY in Subselect

■ Full OUTER join

■ SQE Learning Optimizer

■ RPG Variable scoping at procedure level

■ SQL Syntax highlighting in RDi

■ DB2 Data Studio

■ DB2 Web Query updates

■ Business Intelligence

▶Super Groups

▶CUBE

Page 12: Db2 Data Access with PHP on IBM i - TUG · Db2 Data Access with PHP on IBM i ... ■Can connect to remote IBM i for no extra charge. DB2 & PHP: Improvements. 9 You must be able to

12

i7.1 (April 13, 2010)

■ Technology Refresh

■ XML Data Type

■ Column Level Ecryption

■ Adaptive Query Processing

■ SQE meets CQE

■ Encoded Vector Indexes

■ Technology Refresh 4

▶XMLTABLE, Three part name support

Page 13: Db2 Data Access with PHP on IBM i - TUG · Db2 Data Access with PHP on IBM i ... ■Can connect to remote IBM i for no extra charge. DB2 & PHP: Improvements. 9 You must be able to

13

i7.1/7.2

■ Technology Refresh 5

▶ iNav DB Enhanced UI,

■ Technology Refresh 6 & 7

▶ SQL Index to 1.7TB, Live table/Index move to SSD

■ Technology Refresh 8

▶ GENERATE_SQL(), Performance Enhancements

■ Technology Refresh 9, 7.2 TR1

▶ Pipelined Table Functions, RegEX, Faster iASP Vary On

■ Technology Refresh 10, 7.2 TR2

▶ REPLACE table, JSON, CPU & I/O averages on Show statements

■ Technology Refresh 11, 7.2 TR3

▶ SQL ILE & ILE RPG Sync, SQE Enhancements

Page 14: Db2 Data Access with PHP on IBM i - TUG · Db2 Data Access with PHP on IBM i ... ■Can connect to remote IBM i for no extra charge. DB2 & PHP: Improvements. 9 You must be able to

DB2 & PHP: Default Connection

Page 15: Db2 Data Access with PHP on IBM i - TUG · Db2 Data Access with PHP on IBM i ... ■Can connect to remote IBM i for no extra charge. DB2 & PHP: Improvements. 9 You must be able to

15

Shipped defaults

■ Look at Samples…

■ *LOCAL – when you really aren’t sure

■ Zero length string for USER & PASSWORD

■ Options parameter is optional.

■ This is Anonymous

Page 16: Db2 Data Access with PHP on IBM i - TUG · Db2 Data Access with PHP on IBM i ... ■Can connect to remote IBM i for no extra charge. DB2 & PHP: Improvements. 9 You must be able to

16

Default User profile

■ Runs as QTMHHTTP

■ Can be disabled…

Page 17: Db2 Data Access with PHP on IBM i - TUG · Db2 Data Access with PHP on IBM i ... ■Can connect to remote IBM i for no extra charge. DB2 & PHP: Improvements. 9 You must be able to

17

Connection Error

■ Disabled profile…IBM i security enforced!

Page 18: Db2 Data Access with PHP on IBM i - TUG · Db2 Data Access with PHP on IBM i ... ■Can connect to remote IBM i for no extra charge. DB2 & PHP: Improvements. 9 You must be able to

18

Hardcoded library

■ Library in SQL statement

■ All rows retrieved as arrays

Page 19: Db2 Data Access with PHP on IBM i - TUG · Db2 Data Access with PHP on IBM i ... ■Can connect to remote IBM i for no extra charge. DB2 & PHP: Improvements. 9 You must be able to

19

Which retrieval method?

■ Difference is column names in index

■ Benchmarks via Z-Ray on micro-partition

DB2_fetch_array()21 ms

DB2_fetch_assoc()24 ms

DB2_fetch_both()39 ms

Page 20: Db2 Data Access with PHP on IBM i - TUG · Db2 Data Access with PHP on IBM i ... ■Can connect to remote IBM i for no extra charge. DB2 & PHP: Improvements. 9 You must be able to

DB2 & PHP: options for *LIBL

Page 21: Db2 Data Access with PHP on IBM i - TUG · Db2 Data Access with PHP on IBM i ... ■Can connect to remote IBM i for no extra charge. DB2 & PHP: Improvements. 9 You must be able to

21

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 22: Db2 Data Access with PHP on IBM i - TUG · Db2 Data Access with PHP on IBM i ... ■Can connect to remote IBM i for no extra charge. DB2 & PHP: Improvements. 9 You must be able to

22

Single library approach

■ Similar to the world of MySQL/MariaDB.

Page 23: Db2 Data Access with PHP on IBM i - TUG · Db2 Data Access with PHP on IBM i ... ■Can connect to remote IBM i for no extra charge. DB2 & PHP: Improvements. 9 You must be able to

23

Multiple libraries hardcoded in PHP

■ More like real life

Page 24: Db2 Data Access with PHP on IBM i - TUG · Db2 Data Access with PHP on IBM i ... ■Can connect to remote IBM i for no extra charge. DB2 & PHP: Improvements. 9 You must be able to

24

Job Description – PHPUSER2

■ WRKJOBD, DSPJOBD

Page 25: Db2 Data Access with PHP on IBM i - TUG · Db2 Data Access with PHP on IBM i ... ■Can connect to remote IBM i for no extra charge. DB2 & PHP: Improvements. 9 You must be able to

25

Multiple libraries via User Profile

■ Parallels Green Screen access

Page 26: Db2 Data Access with PHP on IBM i - TUG · Db2 Data Access with PHP on IBM i ... ■Can connect to remote IBM i for no extra charge. DB2 & PHP: Improvements. 9 You must be able to

DB2 & PHP: ibm_db2.ini

Page 27: Db2 Data Access with PHP on IBM i - TUG · Db2 Data Access with PHP on IBM i ... ■Can connect to remote IBM i for no extra charge. DB2 & PHP: Improvements. 9 You must be able to

27

php.ini

■ File in IFS:

■ Zend Server Admin GUI port 10081 or 10091

Page 28: Db2 Data Access with PHP on IBM i - TUG · Db2 Data Access with PHP on IBM i ... ■Can connect to remote IBM i for no extra charge. DB2 & PHP: Improvements. 9 You must be able to

28

Block anonymous

■ Samples shipped usually work

■ Default setting is “ON”

■ Default profile is QTMHHTTP

■ Change requires restart of Zend Server PHP

Page 29: Db2 Data Access with PHP on IBM i - TUG · Db2 Data Access with PHP on IBM i ... ■Can connect to remote IBM i for no extra charge. DB2 & PHP: Improvements. 9 You must be able to

DB2 & PHP: Column Heading

Page 30: Db2 Data Access with PHP on IBM i - TUG · Db2 Data Access with PHP on IBM i ... ■Can connect to remote IBM i for no extra charge. DB2 & PHP: Improvements. 9 You must be able to

30

Column Heading Text

■ Column names are nice, but…

■ Column heading and text are not available via functions in the DB2 Extension.

■ Table qsys2/syscolumns contains these values

■ Retrieve them when needed

■ Build function to add to application set

Page 31: Db2 Data Access with PHP on IBM i - TUG · Db2 Data Access with PHP on IBM i ... ■Can connect to remote IBM i for no extra charge. DB2 & PHP: Improvements. 9 You must be able to

31

gettableColumns

Page 32: Db2 Data Access with PHP on IBM i - TUG · Db2 Data Access with PHP on IBM i ... ■Can connect to remote IBM i for no extra charge. DB2 & PHP: Improvements. 9 You must be able to

DB2 & PHP: Featured Functions

Page 33: Db2 Data Access with PHP on IBM i - TUG · Db2 Data Access with PHP on IBM i ... ■Can connect to remote IBM i for no extra charge. DB2 & PHP: Improvements. 9 You must be able to

33

db2_xxxx()

■ Over 50 functions that make up the DB2 extension for PHP.

■ Worth the time to review each

■ We’ll talk about a few interesting ones.

Page 34: Db2 Data Access with PHP on IBM i - TUG · Db2 Data Access with PHP on IBM i ... ■Can connect to remote IBM i for no extra charge. DB2 & PHP: Improvements. 9 You must be able to

34

db2_pconnect()

■ Creates connection that is reusable over multiple page requests.

■ Saves the time of opening and closing the job

■ Same parameters as db2_connect()

■ First request sets everything up

■ Subsequent request from user will reuse job.

Page 35: Db2 Data Access with PHP on IBM i - TUG · Db2 Data Access with PHP on IBM i ... ■Can connect to remote IBM i for no extra charge. DB2 & PHP: Improvements. 9 You must be able to

35

Column(Field) Information

■ Many detail about each column can be obtained

■ Must have valid result set.

Page 36: Db2 Data Access with PHP on IBM i - TUG · Db2 Data Access with PHP on IBM i ... ■Can connect to remote IBM i for no extra charge. DB2 & PHP: Improvements. 9 You must be able to

36

Auto Increment Field

■ Create the table

■ Insert the row

■ Retrieve the unique ID

Page 37: Db2 Data Access with PHP on IBM i - TUG · Db2 Data Access with PHP on IBM i ... ■Can connect to remote IBM i for no extra charge. DB2 & PHP: Improvements. 9 You must be able to

37

Auto Increment Field

Page 38: Db2 Data Access with PHP on IBM i - TUG · Db2 Data Access with PHP on IBM i ... ■Can connect to remote IBM i for no extra charge. DB2 & PHP: Improvements. 9 You must be able to

38

Securityis no laughing matter

■ Security is better and this helps!

Page 39: Db2 Data Access with PHP on IBM i - TUG · Db2 Data Access with PHP on IBM i ... ■Can connect to remote IBM i for no extra charge. DB2 & PHP: Improvements. 9 You must be able to

39

Frist, filter your inputs

■ Developer is agent of security in web app design

■ Filter inputs (Frameworks do this but so does PHP!)

■ JavaScript may do this, but PHP should, too

Page 40: Db2 Data Access with PHP on IBM i - TUG · Db2 Data Access with PHP on IBM i ... ■Can connect to remote IBM i for no extra charge. DB2 & PHP: Improvements. 9 You must be able to

40

Understand which “exec” to use

■ DB2_Exec

▶Fire and forget

▶Use when no parameters necessary

● $sql = “select * from sp_cust”

■ DB2_Execute

▶Prepared SQL via DB2_Prepare & DB2 bind

▶Always use when using parameters

▶Example in Samples

● $sql = “select * from sp_cust where custno = $customerNumber”

Page 41: Db2 Data Access with PHP on IBM i - TUG · Db2 Data Access with PHP on IBM i ... ■Can connect to remote IBM i for no extra charge. DB2 & PHP: Improvements. 9 You must be able to

41

Prepared SQL

■ SQL statement has “?” for placeholder

■ db2_prepare

■ db2_bind_param

■ db2_execute

Page 42: Db2 Data Access with PHP on IBM i - TUG · Db2 Data Access with PHP on IBM i ... ■Can connect to remote IBM i for no extra charge. DB2 & PHP: Improvements. 9 You must be able to

DB2 & PHP: Featured Functions

Page 43: Db2 Data Access with PHP on IBM i - TUG · Db2 Data Access with PHP on IBM i ... ■Can connect to remote IBM i for no extra charge. DB2 & PHP: Improvements. 9 You must be able to

43

Data Cache

■ Green screen lookup window vs. drop down

■ Data Cache (Zend or APC) saves data in memory

■ Performance

■ White paper

■ Better performance for frequently access lists

■ Less stress on DB2

■ Aggregate values (BI)

■ Look at examples…

Page 44: Db2 Data Access with PHP on IBM i - TUG · Db2 Data Access with PHP on IBM i ... ■Can connect to remote IBM i for no extra charge. DB2 & PHP: Improvements. 9 You must be able to

44

Standard DB2 Call

■ 350+ Customer Orders

Page 45: Db2 Data Access with PHP on IBM i - TUG · Db2 Data Access with PHP on IBM i ... ■Can connect to remote IBM i for no extra charge. DB2 & PHP: Improvements. 9 You must be able to

45

DB2 Call with Data Cache

Page 46: Db2 Data Access with PHP on IBM i - TUG · Db2 Data Access with PHP on IBM i ... ■Can connect to remote IBM i for no extra charge. DB2 & PHP: Improvements. 9 You must be able to

THANK YOU

Mike Pavlak

[email protected]