decorative image for blog on ibm i 7.5 for php
August 30, 2023

IBM i 7.5 for PHP: Exploring Db2 Services

IBM i
PHP Development

With each new release of the IBM i operating system, and the various technology refreshes that come alongside them, we see amazing new features and enhancements that improve the development experience on IBM i. IBM i 7.5 is no different.

In this blog, I'll look at a few of those features available with IBM i 7.5 and/or released as part of a recent technology refresh. I will also discuss the benefits IBM i 7.5, including new and improved Db2 services, can provide to PHP users in particular.

Back to top

IBM i 7.5 Overview

IBM i 7.5, which released in May 2022, introduced a number of features and improvements to the IBM i platform. While I could spend the better part of a year unpacking and describing IBM i 7.5's improvements and their impact, today I want to look at the key features for teams using IBM i and PHP.

With that in mind, the biggest quality of life improvement for teams working with IBM i and PHP is the addition of new Db2 services.

Back to top

PHP Toolkit for IBM i, Meet Db2 Services

Back in 2005 when PHP was first coming to the platform, the folks at Zend asked me and several others what was needed to make PHP attractive. Hands down, we all chimed in with feedback that eventually became the PHP Toolkit for IBM i. Two iterations later, the toolkit is alive and well and still being maintained. But several of the features that were once the exclusive domain of the illustrious PHP Toolkit have since been made available as Db2 Services, including features like accessing spooled files, data areas, output queues, and more.

Performance and Resilience Improvements

One additional benefit of these new Db2 services is that they are lightning fast. Often, I hear IBM i folks talking about performance, and this is a clear winner when upgrading your system and PHP stack. Not only are PHP and the new POWER10 systems faster, but these services run circles around the old Toolkit as there is no XML translation required. 

In addition, the new and improved Db2 services tend to be a bit more resilient since there are so few moving parts. The examples shown were run on ZendPHP with PHP 8.2 and a Power10 server running IBM i 7.5 and the code just flies.

Boolean Data Type

Seeing support for the new Boolean data type is attractive as more and more APIs are dependent on upon JSON processing. IBM did not disappoint here with not only the new data type but also full support for the Boolean in the JSON functions inside of SQL.

Spooled Files

The PHP Toolkit for IBM i allowed users to download, print, convert, delete, or retrieve information related to spooled files. With the release of IBM i 7.5, that functionality is available as a set of commands in Db2 (covered below).

Data Areas

Here is a very simple example of retrieving all the data areas in a library and displaying their contents in a web page. This took many lines of code using the toolkit, but now only a few thanks to the new Db2 services that Scott Forstie and the IBM i team have developed. 

As an example, here is the PHP code for generating list of data areas and their values for a given library:

echo ("<h2>Data Area Examples</h2>");
$conn = db2_connect('*LOCAL', '', '');
$query = "SELECT DATA_AREA_NAME, DATA_AREA_VALUE FROM QSYS2.DATA_AREA_INFO
  WHERE DATA_AREA_LIBRARY = 'ZENDPHP74';";
$result = db2_exec($conn, $query);
echo "<pre>";
while ($row = db2_fetch_array($result)) {
    echo "DATA_AREA_NAME: " . $row[0] . "<br />";
    echo "DATA_AREA_VALUE: " . $row[1] . "<br /><br />";
}
echo "</pre>";
db2_close($conn);

That code outputs as:

 

image showing data area examples from zend blog on db2 services

 

Output Queues

The PHP Toolkit for IBM i gives users a way to manage output queues, including listing of available output queues, submit output to output queues, as well as manage and monitor output queues. With IBM i 7.5, that functionality is now available via set of commands in Db2 (listed below).

Back to top

How to Take Advantage of the New Db2 Services and IBM i 7.5

The mantra of the RPG community is simpe: "If it works, don't fix it." But I have to argue that there is always an opportunity to address technical debt. I prefer to say something like, "Please leave the code a little better than you found it." Updating these toolkit calls to use Db2 services is a great first step. 

Here is an example of some of the mappings of the toolkit calls to Db2 Services.

Toolkit Function

Db2 Service

Data Area

DATA_AREA_INFO (View and function)

Spooled File

OUTPUT_QUEUE_ENTRIES() (View and function) 
QSYS2.OUTPUT_QUEUE_INFO 
SPOOLED_FILE_INFO() 
DELETE_OLD_SPOOLED_FILES() 
GENERATE_PDF() 
SPOOLED_FILE_DATA()

User Spaces

CHANGE_USER_SPACE() 
CHANGE_USER_SPACE_ATTRIBUTES() 
CREATE_USER_SPACE() 
USER_SPACE() 
USER_SPACE_INFO

Data Queues

CLEAR_DATA_QUEUE() 
DATA_QUEUE_ENTRIES() 
DATA_QUEUE_INFO 
SEND_DATA_QUEUE() 
RECEIVE_DATA_QUEUE()

System Values

SYSTEM_VALUE_INFO

Active Jobs

ACTIVE_JOB_INFO() 
JOB_INFO()

Object Information

OBJECT_STATISTICS() 
OBJECT_OWNERSHIP 
OBJECT_PRIVILEGES() (View and function) 
OBJECT_PRIVILEGES 
(And a bunch for the IFS, too!)

Back to top

ODBC Example Using Db2 Services for IBM i 7.5

Above, I illustrated an example using the standard Db2 PHP interface. Now it’s time to look at an ODBC example. 

Here we are using nothing but Db2 services to collect information from a brand new service created for IBM i 7.5. This code might be even tighter because in addition to using ODBC we are also using PHP Data Objects or PDO. This construct abstracts a lot of the busy work in coding and renders it a bit cleaner.

 $dsn = 'odbc:*LOCAL';
$db = new PDO($dsn, $user, $password);
$URL = "google.com";
$sql = "SELECT * FROM TABLE(QSYS2.DNS_LOOKUP('$URL'))";
$data=$db->query($sql,PDO::FETCH_ASSOC);
echo ("<h2>IPs for URL</h2>");
foreach ($data as $row) {
    print( "Type: " . $row['ADDRESS_SPACE_TYPE']);
    print( "  IP: " . $row['IP_ADDRESS'] . "<br>");
}

 

image showing IPs for URL during ODBC demo with Db2

 

Back to top

Final Thoughts

While the Db2 services changes above might seem like a limited benefit at a glance, the performance and resilience benefits are nothing to scoff at. When you take into account the updated support functionality included in the various operating systems and technologies used alongside IBM i, there will be ample reason for teams to upgrade IBM i versions to IBM i 7.5.

Try Our PHP Builds on IBM i 7.5 for Free

Zend Server and ZendPHP now support IBM i 7.5, making it easier than ever to deploy and scale your PHP. Try for free via the links below.

Try Zend Server   Try ZendPHP

Additional Resources

Back to top