Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create simple-parameters.php #205

Merged
merged 1 commit into from
Sep 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions samples/simple-parameters.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

// Example with simple parameters.
// This example contains no data structures, arrays, or procedures. Those are illustrated in other examples.

require_once('ToolkitService.php');

// Connect to toolkit using DB2 credentials (can also leave blank for default authority)
// There are also other transports available.. PDO_ODBC and local, to name two (see examples).
$conn = ToolkitService::getInstance('*LOCAL', 'MYUSER', 'MYPASS');

// set stateless mode for easy testing (no 'InternalKey' needed).
$conn->setOptions(array('stateless'=>true));

// Define several input/output params
// (To see all available data types, see: samples/data-types.md)
$params = []; // start with empty array
$params[] = $conn->AddParameterChar('in', 1,'Division', 'DIV', 'A');
$params[] = $conn->AddParameterChar('in', 6,'Product', 'PROD', '123456');
$params[] = $conn->AddParameterPackDec('both', 7, 2, 'Quantity', 'QTY', '4.53');
$params[] = $conn->AddParameterZoned('out', 5, 2, 'Price', 'PRICE', '0');

// Call program.
// In this example, assume your program is MYLIB/MYPGM.
$result = $conn->PgmCall('MYPGM', 'MYLIB', $params);

if (!$result) {
echo 'Error calling program. Code: ' . $conn->getErrorCode() . ' Msg: ' . $conn->getErrorMsg();
} else {
echo 'Called program successfully.<BR><BR>';
// Parameter values that are I/O type "out" or "both" will be available in $result['io_param'].
echo 'Input/output params: QTY: ' . $result['io_param']['QTY'] . ' PRICE: ' . $result['io_param']['PRICE'] . '<BR>';
}

/*
The above will output something like:

Called program successfully.

Input/output params: QTY: 4.53 PRICE: 0.00

*/