Archive

Posts Tagged ‘PHP’

Alan Seiden Consulting: PHP and IBM i Expertise › Using procedures and service programs with the PHP Toolkit for IBM i

December 27th, 2012 Comments off

The open source PHP Toolkit enables PHP applications to call procedures (functions) that are defined within RPG service programs on IBM i. (For more information on the toolkit, see my toolkit information page.)

Here’s an example that will work with PHP Toolkit API version 1.4.0 or higher. I also included some ‘boilerplate’ 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.

<?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[] = $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', 'MYINT', '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

*/


Read the original at Alan Seiden Consulting: PHP and IBM i Expertise.

Simply i › Linking IBMi data to a Gauge in PHP

December 13th, 2012 Comments off
We were thinking about how to create a new interface for one of our old utilities using PHP and decided that using a JavaScript based gauge would probably be a good start. There are plenty of free and chargeable JavaScript … Continue reading


Read the original at Simply i.

Simply i › Adding configuration Capabilities to the HA4i PHP Interfaces

December 7th, 2012 Comments off
We have been developing the management interface for HA4i our High Availability product in PHP for some time, but we had not got round to looking at how we could extend that interface to allow us configure the various elements … Continue reading


Read the original at Simply i.

Simply 'i' › Capturing the return value from a function

November 28th, 2012 Comments off
As a C programmer I have become used to using the return values set by a function as an indicator of the success of the function to carry out its intended role, so when I created Service programs I used the same process. This raised a question about how I could capture that return value [...]


Read the original at Simply 'i'.

Simply 'i' › A Bit more fun with the File display and update web pages.

November 23rd, 2012 Comments off
OK so we thought we would have a bit more fun with the previous programs which allowed you to move around and update file records. This is very basic code so don’t expect too much, but as we always say it’s free and you can do what you want with it (or not!). We were [...]


Read the original at Simply 'i'.

Simply 'i' › Interesting discussion about XMLSERVICE and big data

November 23rd, 2012 Comments off
I sometimes worry about how we perceive the Open Source products and what we as developers should expect from it. I like to keep a watch on what is happening within the IBMi/PHP eco system so I tend to watch the various forums looking at what people are doing. I had not been following the [...]


Read the original at Simply 'i'.

Simply 'i' › Next stage of the DB2 File updater

November 23rd, 2012 Comments off
Previously we created a simple file output page which we said could be used to update a DB2 file in much the same way as the PHPMyAdmin interface allows where a single record is displayed which allows the user to move around the records and update fields where necessary. That example did not allow the [...]


Read the original at Simply 'i'.

Simply 'i' › Walking through a DB2 PF data and allow update.

November 22nd, 2012 Comments off
I was thinking about some of the tools I would like to see on the IBMi and written in PHP that allow you to carry out the same functionality as the PHPMyAdmin tool on MySQL. Not that I wanted to write the entire product but at times I would like the ability to just review [...]


Read the original at Simply 'i'.

Alan Seiden's PHP and IBM i Resources › ZF2 and DB2 for IBM i

October 16th, 2012 Comments off

I’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’m following the development of a similar adapter for ZF2.

Q. Does ZF 2 include an adapter for DB2?
A. ZF 2.0 does not, but read on.

Q. When will a DB2 adapter be included in ZF 2.x?
A. Rumor says ZF 2.1 or 2.2. I plan to discuss it with the Zend Framework team at ZendCon in a week or two (late October, 2012).

Q. Does Alan’s IBM i-friendly DB2 adapter for Zend Framework 1.x work in 2.x?
A. No. Because ZF’s Zend_Db equivalent in 2.x works differently than in 1.x, my 1.x component will not work in 2.x.

Q. When will you know more?
A. I’ll know more after ZendCon, so probably late October/early November. I plan to spend time with the db adapter team at the conference. We’ll discuss the needs of IBM i users, such as support for driver-specific features, including library lists.

Q. Help! I must use ZF2 now.
A. You can still use the underlying functions in the ibm_db2 driver (db2_connect, db2_exec, etc.). I know one person creating his own bare-bones adapter based on these. For most people, though, it’s best to wait for the official announcement.

I’ll update this blog post after ZendCon.


Read the original at Alan Seiden's PHP and IBM i Resources.

Alan Seiden Consulting: PHP and IBM i Expertise › ZF2 and DB2 for IBM i

October 16th, 2012 Comments off

I’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.


Read the original at Alan Seiden Consulting: PHP and IBM i Expertise.