<?php
require_once('ToolkitService.php');
// connect to toolkit using DB2 credentials (can also leave blank for default authority)
try {
$conn = ToolkitService::getInstance('*LOCAL', 'MYUSER', 'MYPASS');
} catch (Exception $e) {
// Determine reason for failure.
// Probably database authentication error or invalid or unreachable database.
$code = $e->getCode();
$msg = $e->getMessage();
switch ($code) {
case 8001:
// "Authorization failure on distributed database connection attempt"
// Usually means a wrong DB2 user or password
echo 'Could not connect due to wrong user or password.';
break;
case 42705:
echo 'Database not found. Try WRKRDBDIRE to check.';
break;
default:
echo 'Could not connect. Error: ' . $code . ' ' . $msg;
break;
} //(switch)
die; // couldn't connect...handle this however you wish
} //(try/catch)
// set stateless mode for easy testing (no 'InternalKey' needed).
// (setOptions() introduced in v1.4.0)
$conn->setOptions(array('stateless'=>true));
/* If you wish to test this script but you don't have a real service program,
* use parseOnly and parseDebugLevel as shown below.
* No program will be called and you'll get your original values back.
* Simply uncomment the next line to try this great testing feature of the toolkit.
*/
//$conn->setOptions(array('parseOnly'=>true, 'parseDebugLevel'=>1));
// define several input/output params
$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');
// define a procedure return param. Can be any type, even a data structure
$retParam = $conn->AddParameterInt32('out', '4-byte int', 'MYRESULT', '13579');
/* Call service program procedure.
* In this example, assume your program is MYLIB/MYPGM and has a procedure/function 'myproc'
* (procedure name is case-sensitive).
* Note: specify optional procedure name in parameter 5, an array with associative index 'func'.
*/
$result = $conn->PgmCall('MYPGM', 'MYLIB', $params, $retParam, array('func'=>'myproc'));
if (!$result) {
echo 'Error calling program. Code: ' . $conn->getErrorCode() . ' Msg: ' . $conn->getErrorMsg();
}
echo 'Called program successfully.<BR><BR>';
echo 'Input/output params: QTY: ' . $result['io_param']['QTY'] . ' PRICE: ' . $result['io_param']['PRICE'] . '<BR>';
echo 'Procedure return param MYRESULT: ' . $result['retvals']['MYRESULT'];
/*
The above will output something like:
Called program successfully.
Input/output params: QTY: 4.53 PRICE: 0.00
Procedure return param MYRESULT: 13579
*/
Calling procedures and service programs with the PHP Toolkit for IBM i
/14 Comments/in IBM i, PHP /by Alan SeidenCalling procedures in RPG service programs, including getting the return value, is a powerful feature of the PHP Toolkit. The sample script below demonstrates how it’s done.
Note: Make sure your procedure name is 100% correct. It is case-sensitive. If you get an error, run the following command (replacing LIBNAME/PGMNAME with your library and program names) and look for your procedure name in the output. The command:
DSPSRVPGM SRVPGM(LIBNAME/PGMNAME) DETAIL(*PROCEXP)
The example below includes ‘boilerplate’ code to show best practices for connecting to the toolkit and checking for a successful connection. The illustration of how to call a procedure is in the second half.
For more information on the toolkit, see our toolkit information page or get in touch.
ZF2 and DB2 for IBM i
/11 Comments/in Db2 for i, IBM i, Open Source, PHP /by Alan SeidenI’d like to address questions about DB2 support in Zend Framework 2.x. Because I helped create the IBM i-friendly DB2 adapter for Zend Framework 1.x, I’ve followed the development of a similar adapter for ZF2.
(updated January 30, 2013, upon the release of ZF 2.1)
Q. Does ZF 2 include an adapter for DB2?
A. Yes! Starting with ZF 2.1, which was released today.
Q. Is Alan’s IBM i-friendly DB2 adapter for Zend Framework 1.x needed in 2.x?
A. No. Because ZF’s Zend_Db equivalent in 2.x works differently than in 1.x, my 1.x component is not needed in 2.x.
Q. Does ZF 2.1’s DB2 adapter work with IBM i?
A. Yes! Please try it and provide feedback to the ZF team.
Alan Seiden Consulting LLC
/4 Comments/in Db2 for i, IBM i, News & Events, PHP /by Alan SeidenI’ve started a consulting firm dedicated to helping companies attain superior results with PHP, Zend Framework, IBM i, and related technologies such as Zend Server, DB2, and the new PHP toolkit.
We will provide guidance and best practices, training, mentoring, troubleshooting, performance help, team building, speaking, writing, and advocacy.
My first speaking engagement with my new company will be the OCEAN conference on July 20, 2012, in Southern California. Hope to see some of you there.
Thanks for your support. I will be available starting July 2 after a short vacation. I look forward to working with you.
Alan
Which version of Zend Server for IBM i do I have?
/3 Comments/in IBM i, PHP, Web development /by Alan SeidenUPDATE: As of 2020, we recommend using Seiden PHP on IBM i and LINUX for reliability, speed, and ease of maintenance.
Updated December 20, 2017
Here is the easiest way to learn the version of Zend Server installed on an IBM i system.
From a 5250 command line, follow these four steps:
On my IBM i, I see:
7PHPZND *INSTALLED Zend Server for IBM i 9.1.2 ( PHP 7.1 )
so Zend Server is at 9.1.2 and PHP is 7.1.
Thanks to Zend’s Sam Pinkhasov for this tip.
Toolkit webcast tomorrow, April 5
/0 Comments/in Apache, Db2 for i, IBM i, News & Events, PHP, Web development /by Alan SeidenTomorrow I’m presenting a new webcast, New PHP Toolkit from Zend and IBM: Open Source on IBM i, as part of System i Network’s free “Virtual Conference.”
Date: Thursday, April 5
Time: 11:15am ET
Registration (free): http://tinyurl.com/new-toolkit-20120405
Other presentations in the virtual conference include Jon Paris explaining why PHP is an excellent strategic choice on IBM i, two talks on mobile technology, and more.
I invite you to watch the webcast, ask questions, and learn more about the new toolkit.
Web performance webinar today
/3 Comments/in Apache, Db2 for i, IBM i, News & Events, Performance, PHP, Web development /by Alan SeidenHope you can join me for “Web performance first aid,” a webcast for the COMMON user group. The webcast will be recorded and archived for future listenings as well.
The webcast is for COMMON members, so anyone wanting to hear it needs to join COMMON.
I based the presentation on my consulting practice that helps ensure high performance for PHP and Zend Framework applications on IBM i. Good performance is critical for customer acceptance of web sites and mobile applications.
Webcast link: http://www.common.org/index.php/webcasts/upcoming-webcasts.html
Anyone wishing to see just the slides can do that on my site: http://alanseiden.com/presentations and look for “Web performance first aid.”
Before you remove Zend Core from your IBM i
/0 Comments/in IBM i, PHP /by Alan SeidenUPDATE: As of 2020, we recommend using Seiden PHP on IBM i and LINUX for reliability, speed, and ease of maintenance.
If you’ve installed Zend Server for IBM i and are planning to remove the older Zend Core for i5/OS, first check that Zend Core’s version is at least 2.6.1.
Zend Core must be at 2.6.1+ because if you uninstall version 2.6.0 or lower, portions of Zend Server will be uninstalled as well. Therefore, update your old Zend Core to 2.6.1+ before uninstalling.
Resources
(Outdated links removed)
We’ve been named a Top 10 IBM i blog
/1 Comment/in IBM i, News & Events, PHP /by Alan SeidenThis blog, alanseiden.com, has been named to the “Best i Blog Bets” top 10 list by Alex Woodie, Senior Editor of IT Jungle.
Thank you to Alex for this honor. This site will continue to offer articles, presentations, event listings, and news about PHP, Zend Framework, IBM i, and other topics of interest to the PHP/i community.
Zend/PHP 2011 Photos, Part 1 (IBM i)
/0 Comments/in IBM i, PHP /by Alan SeidenIBM i had a solid presence at ZendCon, the Zend/PHP conference. IBM itself was a sponsor and staffed a booth (Tim Rowe and Tony Cairns). Here are a few photos from the conference. I’ll post more when I get time.
PHP/IBM i pin given out at IBM booth at ZendCon 2011
Chris Pharo from Crosspointe, LLC, demonstrating how their "TERMS 2020" school district ERP package evolved from a green screen interface to PHP/web, all on IBM i
Alan with elePHPant
Zend Framework DB2 adapter for IBM i
/11 Comments/in Db2 for i, PHP /by Alan SeidenI recently received a question about how to use DB2 with Zend Framework on IBM i. Thomas wrote:
I told Thomas about an improved DB2 adapter, optimized for IBM i, that I’d created in cooperation with Zend. Its usage is explained in my presentation, “From Zero to ZF.”
Thomas wrote back to say this adapter worked perfectly for him, eliminating the error and improving performance. I believe this DB2 adapter (or something similar) will eventually be included with Zend Framework 2.0, but until then, it works well as a custom adapter.