From YiPs Wiki (i powered)

XMLService: XMLSERVICEPHP Day One XML

(click to open)

Quick Page Table of Contents

Scanning…

Day One PHP Using XML Interface

Under construction.

Goto Main Page
Goto Documents

           -----------------------------------------
           |              Browser                  |
           |---------------------------------------|
IBM i ---->| Download RPG (1) | Download PHP (2)   |
           | 1) XMLSERVICE    | a) PHP CW Toolkit  |
           |    HTML/XML/REST | b) New PHP Toolkit |
           |    no PHP        |--------------------|
           |    (xmlcgi.pgm)  | c) PHP Raw XML   | <--- PHP Using XML Interface
           |    (optional)    |   (ibm_db2, odbc)  |
           |                  |--------------------|
           | 2) XMLSERVICE DB2 stored procedures   |
           |    (iPLUG4K, iPLUG32K, ..., iPLUG15M) |
           | 3) XMLSERVICE (xmlservice.pgm)        |
           |    call most anything on IBM i ...    |
           |    (PGM, SRVPGM, PASE, DB2, etc.)     |
           ------------------------------------------

Who is this page for?

Instructions designed for IBM i developer learning PHP starting from ground zero …

Pick a driver (any driver) …

The following information can be skipped, but after you try a few examples (and they just work), you may want to come back here to step 1 to understand exactly what is going on. You can download everything, so feel free to copy/improve the mini-drivers for your own use.

XMLERVICE is designed run over nearly any connection remote/local IBM i, because input/output is simple XML (just a big string). However, for performance reasons most people simply use one of the many DB2 drivers that are lying about their laptops or IBM i. If you want to see specifics about DB2 connections check out this link {PHP DB2 Connections}.

XMLSERVICE download includes iPLUGxxx stored procedures enabling any DB2 connection discussed {PHP DB2 Connections}, allowing you to call XMLSERVICE from laptops, natively on IBM i, or remotely IBM i-2-IBM i. XMLSERVICE provides multiple iPLUGxxx sizes ranging from iPLUG4K to iPLUG15M, so that you can customise amount of data running back/forth between client/xmlservice. Some DB2 drivers support IN/OUT parameters for iPLUGxxx (PHP ibm_db2, pdo_ibm), but for other drivers a result set version iPLUGRxxx is also included (PHP odbc):

Stored procedure with in/out XML call (one call and output xml is OUT CLOB):
iPLUG4K(IN IPC CHAR(1024), IN CTL CHAR(1024),IN CI CLOB(4K), OUT C0 CLOB(4K))
iPLUG32K(IN IPC CHAR(1024), IN CTL CHAR(1024), IN CI CLOB(32000), OUT CO CLOB(32000)) 
iPLUG65K(IN IPC CHAR(1024), IN CTL CHAR(1024), IN CI CLOB(65K), OUT CO CLOB(65K)) 
iPLUG512K(IN IPC CHAR(1024), IN CTL CHAR(1024), IN CI CLOB(512K), OUT CO CLOB(512K)) 
iPLUG1M(IN IPC CHAR(1024), IN CTL CHAR(1024), IN CI CLOB(1M), OUT CO CLOB(1M)) 
iPLUG5M(IN IPC CHAR(1024), IN CTL CHAR(1024), IN CI CLOB(5M), OUT CO CLOB(5M)) 
iPLUG10M(IN IPC CHAR(1024), IN CTL CHAR(1024), IN CI CLOB(10M), OUT CO CLOB(10M)) 
iPLUG15M(IN IPC CHAR(1024), IN CTL CHAR(1024), IN CI CLOB(15M), OUT CO CLOB(15M)) 
-- or --
Stored procedure with result set XML call (multiple calls to fetch xml output):
iPLUGR4K(IN IPC CHAR(1024), IN CTL CHAR(1024), IN CI CLOB(4K)) 
iPLUGR32K(IN IPC CHAR(1024), IN CTL CHAR(1024), IN CI CLOB(32000)) 
iPLUGR65K(IN IPC CHAR(1024), IN CTL CHAR(1024), IN CI CLOB(65K)) 
iPLUGR512K(IN IPC CHAR(1024), IN CTL CHAR(1024), IN CI CLOB(512K)) 
iPLUGR1M(IN IPC CHAR(1024), IN CTL CHAR(1024), IN CI CLOB(1M)) 
iPLUGR5M(IN IPC CHAR(1024), IN CTL CHAR(1024), IN CI CLOB(5M)) 
iPLUGR10M(IN IPC CHAR(1024), IN CTL CHAR(1024), IN CI CLOB(10M)) 
iPLUGR15M(IN IPC CHAR(1024), IN CTL CHAR(1024), IN CI CLOB(15M)) 

TIP: Psst xmlservice big secret is … DB2 CLOBs mostly automatically take care of all CCSID conversions between client (ASCII) and XMLSERVICE (EBCDIC), and provide well tuned performance curves, and IBM i improves DB2 all the time, so DB2 interface to XMLSERVICE is very nice indeed.

Let’s look DB2 drivers used in examples:

Some of DB2 drivers can add junk back records (version dependent), but XMLSERVICE returns nicely consistent end of XML keywords that allow a simple routine to cut off the junk. (Yes of course we are working to fix these things, but versions tend to live forever on some machines … cough … V5R4):

XMLSERVICE XML input/output is same over any DB2 driver remote/local (nothing changes), so for examples we will use a simple web technique to switch between calls to $xmlout = xmlservice($xmlin) .

xmlservice_drivers.php:
// *** which xmlservice transport driver? ***
// http://ibmi/test.php?driver=ibm_db2
$driver = 'ibm_db2';
if (isset($_GET['driver'])) $driver = $_GET['driver'];
if (isset($_POST['driver'])) $driver = $_POST['driver'];

Last, we need an authorization include for database, user, password:

PHP XML parameters - getxml(parms)

I want to pass input value that is in php variable named $INCHARA. Or I may want to pass a variable from a HTML form.

<?php
include_once 'authorization.php'; 

/* variables */
$INCHARA = "a";
$INCHARB = "b";
$INDEC1 = "11.1111";
$INDEC2 = "222.22";
$INDS1['DSCHARA'] = "x";
$INDS1['DSCHARB'] = "y";
$INDS1['DSDEC1'] = 66.6666;
$INDS1['DSDEC2'] = 77777.77;
$xmlin = xmlZZCALL($INCHARA,$INCHARB,$INDEC1,$INDEC2,$INDS1);
/* normal DB2 call xmlservice.iPLUG5M($ipc,$ctl,$xmlin,$xmlout)  */
$xmlOut = xmlservice($xmlIn);
var_dump($xmlOut);

function xmlZZCALL($INCHARA,$INCHARB,$INDEC1,$INDEC2,$INDS1) {
return "<?xml version='1.0' encoding='ISO-8859-1'?>
<?xml version='1.0'?>
<script>
<pgm name='ZZCALL' lib='XMLSERVICE'>
<parm  io='both'>
   <data type='1A' var='INCHARA'><![CDATA[{$INCHARA}]]></data>
</parm>
<parm  io='both'>
   <data type='1A' var='INCHARB'><![CDATA[{$INCHARB}]]></data>
</parm>
<parm  io='both'>
   <data type='7p4' var='INDEC1'><![CDATA[{$INDEC1}]]></data>
</parm>
<parm  io='both'>
   <data type='12p2' var='INDEC2'><![CDATA[{$INDEC2}]]></data>
</parm>
<parm  io='both'>
  <ds>
   <data type='1A' var='INDS1.DSCHARA'><![CDATA[{$INDS1['DSCHARA']}]]></data>
   <data type='1A' var='INDS1.DSCHARB'><![CDATA[{$INDS1['DSCHARB']}]]></data>
   <data type='7p4' var='INDS1.DSDEC1'><![CDATA[{$INDS1['DSDEC1']}]]></data>
   <data type='12p2' var='INDS1.DSDEC2'><![CDATA[{$INDS1['DSDEC2']}]]></data>
  </ds>
</parm>
</pgm>
</script>";
}
?>
Retrieved from http://youngiprofessionals.com/wiki/index.php/XMLService/XMLSERVICEPHPDayOneXML
Page last modified on February 14, 2013, at 12:28 PM EST