Skip to content

Commit 04f255e

Browse files
chukShirleyThePrez
authored andcommitted
Add existing PHP samples from Zend
1 parent 7b6de6e commit 04f255e

File tree

4 files changed

+160
-0
lines changed

4 files changed

+160
-0
lines changed

Diff for: samples/classic/display-library-list/example.php

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
include_once 'authorization.php';
3+
include_once 'ToolkitService.php';
4+
5+
try {
6+
$obj = ToolkitService::getInstance($db, $user, $pass);
7+
} catch (Exception $e) {
8+
echo $e->getMessage(), "\n";
9+
exit();
10+
}
11+
12+
$obj->setToolkitServiceParams(array('InternalKey' => "/tmp/$user",
13+
'debug' => true,
14+
'plug' => "iPLUG32K"));
15+
$cmd = "addlible ZENDSVR";
16+
$obj->CLCommand($cmd);
17+
echo "<pre>";
18+
$rows = $obj->CLInteractiveCommand("DSPLIBL");
19+
/*$rows = $obj->CLInteractiveCommand("WRKSYSVAL OUTPUT(*PRINT)");*/
20+
if (!$rows) {
21+
echo $obj->getLastError();
22+
} else {
23+
var_dump($rows);
24+
}
25+
26+
echo "</pre>";
27+
28+
/* Do not use the disconnect() function for "state full" connection */
29+
$obj->disconnect();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
/*
3+
RPG program parameters definition
4+
INCHARA S 1a
5+
INCHARB S 1a
6+
INDEC1 S 7p 4
7+
INDEC2 S 12p 2
8+
INDS1 DS
9+
DSCHARA 1a
10+
DSCHARB 1a
11+
DSDEC1 7p 4
12+
DSDEC2 12p 2
13+
*/
14+
include_once 'authorization.php';
15+
include_once 'ToolkitService.php';
16+
include_once 'helpshow.php';
17+
try {
18+
$ToolkitServiceObj = ToolkitService::getInstance($db, $user, $pass);
19+
} catch (Exception $e) {
20+
echo $e->getMessage(), "\n";
21+
exit();
22+
}
23+
$ToolkitServiceObj->setToolkitServiceParams(array('InternalKey' => "/tmp/$user"));
24+
25+
$IOParam['var1'] = array("in" => "Y", "out" => "");
26+
$param[] = $ToolkitServiceObj->AddParameterChar('both', 1, 'INCHARA', 'var1', $IOParam['var1']['in']);
27+
$IOParam['var2'] = array("in" => "Z", "out" => "");
28+
$param[] = $ToolkitServiceObj->AddParameterChar('both', 1, 'INCHARB', 'var2', $IOParam['var2']['in']);
29+
$IOParam['var3'] = array("in" => "001.0001", "out" => "");
30+
$param[] = $ToolkitServiceObj->AddParameterPackDec('both', 7, 4, 'INDEC1', 'var3', '001.0001');
31+
$IOParam['var4'] = array("in" => "0000000003.04", "out" => "");
32+
$param[] = $ToolkitServiceObj->AddParameterPackDec('both', 12, 2, 'INDEC2', 'var4', '0000000003.04');
33+
$IOParam['ds1'] = array("in" => "A", "out" => "");
34+
$ds[] = $ToolkitServiceObj->AddParameterChar('both', 1, 'DSCHARA', 'ds1', 'A');
35+
$IOParam['ds2'] = array("in" => "B", "out" => "");
36+
$ds[] = $ToolkitServiceObj->AddParameterChar('both', 1, 'DSCHARB', 'ds2', 'B');
37+
$IOParam['ds3'] = array("in" => "005.0007", "out" => "");
38+
$ds[] = $ToolkitServiceObj->AddParameterPackDec('both', 7, 4, 'DSDEC1', 'ds3', '005.0007');
39+
$IOParam['ds4'] = array("in" => "0000000006.08", "out" => "");
40+
$ds[] = $ToolkitServiceObj->AddParameterPackDec('both', 12, 2, 'DSDEC1', 'ds4', '0000000006.08');
41+
//$param[] = array('ds'=>$ds);
42+
$param[] = $ToolkitServiceObj->AddDataStruct($ds);
43+
$result = $ToolkitServiceObj->PgmCall('ZZCALL', "ZENDSVR6", $param, null, null);
44+
if ($result) {
45+
/*update parameters array by return values */
46+
foreach ($IOParam as $key => &$element) {
47+
$element['out'] = $result['io_param'][$key];
48+
}
49+
echo "<br>";
50+
showTableWithHeader(array("Parameter name", "Input value", "Output value"), $IOParam);
51+
} else {
52+
echo "Execution failed.";
53+
}
54+
55+
/* Do not use the disconnect() function for "state full" connection */
56+
$ToolkitServiceObj->disconnect();

Diff for: samples/classic/program-call-two-params/example.php

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
/*
3+
RPG program parameters definition
4+
PLIST
5+
PARM CODE 10
6+
PARM NAME 10
7+
8+
*/
9+
10+
include_once 'authorization.php';
11+
include_once 'ToolkitService.php';
12+
include_once 'helpshow.php';
13+
14+
//The ToolkitService connection method/function uses either IBM_DB2(default)or ODBC extensions to connect
15+
//to IBM i server. In order to switch to ODBC connection assign an "odbc' value to the $extension varibale
16+
//and make sure that the ODBC extension is enabled in the PHP.INI file.
17+
//The ODBC extension usage in ToolkitService is preferable in 2 tier environment: Zend Server running in Windows/Linux
18+
//and accessing database and/or programs in IBM i server
19+
$extension = 'ibm_db2';
20+
try {
21+
$ToolkitServiceObj = ToolkitService::getInstance($db, $user, $pass, $extension);
22+
} catch (Exception $e) {
23+
echo $e->getMessage(), "\n";
24+
exit();
25+
}
26+
27+
$ToolkitServiceObj->setToolkitServiceParams(array('InternalKey' => "/tmp/$user"));
28+
$code = $_POST ['code'];
29+
$desc = ' ';
30+
31+
$param[] = $ToolkitServiceObj->AddParameterChar('both', 10, 'CODE', 'CODE', $code);
32+
$param[] = $ToolkitServiceObj->AddParameterChar('both', 10, 'DESC', 'DESC', $desc);
33+
$result = $ToolkitServiceObj->PgmCall("COMMONPGM", "ZENDSVR6", $param, null, null);
34+
if ($result) {
35+
showTable($result['io_param']);
36+
} else {
37+
echo "Execution failed.";
38+
}
39+
40+
/* Do not use the disconnect() function for "state full" connection */
41+
$ToolkitServiceObj->disconnect();

Diff for: samples/classic/service-program-call/example.php

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
/* This program is calling a service program (*SRVPGM) function which retrieves QCCSID system value
3+
*/
4+
include_once 'authorization.php';
5+
include_once 'ToolkitService.php';
6+
try {
7+
$ToolkitServiceObj = ToolkitService::getInstance($db, $user, $pass);
8+
} catch (Exception $e) {
9+
echo $e->getMessage(), "\n";
10+
exit();
11+
}
12+
$ToolkitServiceObj->setToolkitServiceParams(array('InternalKey' => "/tmp/$user"));
13+
$SysValueName = "QCCSID";
14+
$Err = ' ';
15+
$SysValue = ' ';
16+
17+
$param[] = $ToolkitServiceObj->AddParameterChar('both', 1, 'ErrorCode', 'errcode', $Err);
18+
$param[] = $ToolkitServiceObj->AddParameterChar('both', 10, 'SysValName', 'sysvalname', $SysValueName);
19+
$param[] = $ToolkitServiceObj->AddParameterChar('both', 1024, 'SysValue', 'sysvalue', $SysValue);
20+
$OutputParams = $ToolkitServiceObj->PgmCall('ZSXMLSRV', "ZENDSVR6", $param, NULL, array('func' => 'RTVSYSVAL'));
21+
if (isset($OutputParams['io_param']['sysvalname'])) {
22+
echo " System value " . $SysValueName . " = " . $OutputParams['io_param']['sysvalue'];
23+
} else
24+
echo " Operation failed. System value $SysValueName did not retrieve.";
25+
/*change parameter value and execute again PgmCall()*/
26+
ProgramParameter::UpdateParameterValues($param, array("sysvalname" => "QLANGID"));
27+
$OutputParams = $ToolkitServiceObj->PgmCall('ZSXMLSRV', "ZENDSVR6", $param, NULL, array('func' => 'RTVSYSVAL'));
28+
if (isset($OutputParams['io_param']['sysvalname'])) {
29+
echo " System value " . $SysValueName . " = " . $OutputParams['io_param']['sysvalue'];
30+
} else {
31+
echo " Operation failed. System value $SysValueName did not retrieve.";
32+
}
33+
34+
$ToolkitServiceObj->disconnect();

0 commit comments

Comments
 (0)