Innovate faster and cut risk with PHP experts from Zend Services.
Beginning to advanced PHP classes to learn and earn global certification.
Help me choose >
Submit support requests and browse self-service resources.
IBM i data is stored in Db2 databases. But what's the best way to leverage this data? That's what we break down in this blog. First, let's cover the basics.
A Db2 database is a relational database management system (RDBMS) from IBM. You can use a Db2 database to store and manage your IBM i data.
Modernization is a popular topic in the IBM i community. And it extends to your Db2 databases. Here's how you need to modernize them:
In this blog, you'll learn how to create web-based applications written in PHP that can work with your IBM i data and provide CRUD functionality.
If you've not heard the term CRUD before, it stands for Create, Read, Update, and Delete.
Db2 databases use SQL as the language to access data.
A CRUD-based application can use basic Db2 SQL commands to retrieve, update, and manipulate information in Db2 databases.
The following are the three most common approaches for implementing a PHP, CRUD-based application.
The first approach to talk about is developing your own custom PHP scripts. For this approach, you need to:
Typically, the scripts manage the logic, data presentation, and user-input gathering via HTML. So, when you use this approach, the business logic will not be separate from the data representation.
You could use one monolothic script. Or you could separate the main functions into separate scripts. For example, using CRUD commands, you could write a:
PHP scripts aren't the fastest approach. You'll need to develop custom scripts for each function. No framework would be used. This means that functions — such as connecting to the data store — would need to be implemented several times within the scripts.
This leads to high levels of code repetition. It also can create a difficult situation for maintenance down the road. Imagine having 50 instances and having to change one of these functions?
Scripts can get complex, too. That's because they need to provide forms that are appealing to users and representative of data formats. This requires the retrieval of data-attribute information. And if the data attributes change, you need to change the various forms used to display and manipulate data. And this might possibly be in multiple places throughout the scripts.
You could also use a third-party solution, such as PHPgrid, to unleash your Db2 databases in PHP.
PHPgrid removes much of the minutia you’ll have to manage when you develop custom scripts. In addition, it can be easier to provide a relatively clean display of your data using basic CRUD functionality. For example:
$dg = new C_DataGrid("SELECT * FROM SP_CUST","CUST_ID","SP_CUST");
$dg -> display();
The above code snippet is a complete PHP script that provides the following data grid:
And, it is relatively simple to add additional CRUD functionality. All you need to do is add the following lines to your script:
$sdg = new C_DataGrid("SELECT * FROM ORDER", "CUST_ID", "ORDERS");
The disadvantage of using PHPgrid is that it can be challenging to evolve or scale the application to deliver new functionality. For example, it could be difficult to add a function that uses the records retrieved via PHPgrid as input to an RPG call (via the iToolkit/XMLService).
You could also leverage a PHP framework and middleware, such as the Laminas Project (formerly Zend Framework) and its corresponding middleware solution, Mezzio (formerly Expressive).
If you have been around PHP development for a while, you probably know all about frameworks. If you haven't been exposed to frameworks, don't worry. Here are some definitions that will help:
MVC stands for Model, View, Controller. It is a design paradigm or pattern for managing the requests of web-based applications by separating the:
It’s worth noting that you would use either MVC or middleware to manage your web application’s requests.
You can simplify and streamline the development of web-based, PHP applications that run on the IBM i platform by using frameworks. They eliminate the need to develop the same solution or write the same code over and over again. Frameworks also establish connections between your application and data sources.
Most frameworks, including Laminas, adhere to the Model-View-Controller (MVC) design pattern. The concept behind MVC is to isolate the business logic of an application from user interface considerations. By isolating the business logic from the user interface, it becomes easier to modify either without affecting the other.
The Laminas Project is the new name of Zend Framework!
Zend by Perforce continues to be a major influencer and developer of the Laminas Project. But the framework is now open source from Linux Foundation as the Laminas Project.
It is important to keep in mind that Laminas is not a new framework but rather a continuation of the Zend Framework. This framework has been continuously developed by an extensive community over the last 15 years — and downloaded 400 million times. Additionally, it brings extensibility and testability to PHP applications.
If you prefer to use middleware, you can use Mezzio. It is a subproject of Laminas that provides middleware for building PHP applications that use the PSR-7 (HTTP Messages) and PSR-15 (HTTP Request Handlers) specifications. It also provides a variety of routing and templating options.
PSR stands for PHP Standard Recommendation. PSRs are interfaces or APIs produced by the PHP Framework Interop Group (PHP-FIG) for the purpose of standardizing common application concerns within PHP frameworks and applications. Middleware such as Mezzio is driven, in part, through implementation of various PSRs.
When it comes to developing CRUD applications, the PSRs that matter include:
So why would we want to use middleware? Put simply, middleware:
Frameworks such as Laminas rely on Composer to install and update applications’ various components. When the application structure is first created, a directory structure such as the following is created:
Structure items include:
At a very high level, to create a Mezzio application, you will first use Composer to create the project:
composer create-project mezzio/mezzio-skeleton mezzio
After answering a few questions regarding interfaces for routing and templating, you can start writing your middleware. Generally, the default responses suffice, except when it comes to an engine. You should specify one because the default is to omit it.
Get an example of middleware code >>
You need to modernize your Db2 database. And the best way to do it is with PHP.
You'll be able to unlock data siloes, so that you make use of historic and current data. You can also deliver new services that people take advantage of using their desktops and mobile devices.
Regardless of which method you choose to develop your PHP apps — custom PHP scripts, phpGrid, frameworks such as Laminas, or middleware such as Mezzio — Zend can help.
Our PHP and Laminas experts can help you with your projects by providing:
IBM Champion | Senior Solutions Consultant, Zend, Perforce Software
As an IBM champion, Mr. Earley has been recognized as a leader in the IBM i community and offers more than 20 years of experience helping customers to implement solutions on the platform. His expertise includes using PHP, MariaDB, Docker, and Chef for creating modern enterprise solutions that run on IBM i, as well as PowerVC for cloud deployments and virtualization management. Mr. Earley is a frequent speaker at global technology conferences, and he has authored numerous articles on Linux, PHP, virtualization, systems management, and open source solutions and concepts.