Use PHP scripts to access DB2 UDB for iSeries data with Zend Core for i5/OS


What is PHP?

PHP stands for PHP: Hypertext Preprocessor. PHP is basically a scripting language generally used for rapidly developing Web pages. The best thing about PHP is that it is easy to learn specially for a newcomer. As this article shows you, it's also easy to develop simple PHP scripts that access your DB2 data. You can embed your PHP script within an HTML script and thereby display your DB2 results on a Web page.

What is Zend Core for i5/OS?

Zend Core for i5/OS is fairly new, at the time of writing this article the Early Access Code has been made available for downloading and testing. This product is something to get excited about, because it's the first time that you can develop and run PHP scripts entirely integrated to the i5/OS platform. Prior to this, in order to run PHP, you would need to setup a PASE environment, compile PHP and follow a set of configuration steps. But with the Zend Core product, you can now rapidly develop and deploy PHP scripts natively on i5/OS. With this product you now have the benefit of having an open and integrated PHP environment on your platform of choice, the i5/OS.

What do I do to set up the environment?

The Early Access Release V1.3.1 for Zend Core for i5/OS is used for this article.

On the iSeries server, you need to have the following set up:

  1. You should be at level V5R4 with the latest program temporary fix (PTF).
  2. The /usr/local IFS directory should be created before installing the Zend Core for i5/OS product. If this directory does not exist, then the product installation fails with the errors shown in Figures 1 and 2:
    Figure 1. Installation error
    Installation error
    Installation error

    Figure 2. Installation error
    Installation error
    Installation error
  3. Ensure all the following are installed. You can enter the Go Licensed Program (GO LICPGM) command and select Option 10 (Display) to see if these products are installed on the machine:
    DescriptionProduct optionLicensed program
    Portable App Solutions Environment335722ss1
    System Openness Includes135722ss1
    Digital Certificate Manager345722ss1
    IBM Portable Utilities for i5/OSbase*5733sc1
    OpenSSH, OpenSST, Zlib15733sc1
  4. Finally, to access the Zend Core for i5/OS Administration Console, use Internet Explorer 5.5 and above, with cookies and pop-ups enabled.

Install Zend Core for i5/OS

After checking the prerequisites for the Zend Core product, go ahead and install it.

  1. Create a savf file on the iSeries server using the

    command, and FTP the installation savf file over to the iSeries server into the above savf file.
  2. Restore the object using the following command:
    Figure 3. Restore object
    Restore object
    Restore object
  3. Start the installation as follows. Keep hitting Enter until you reach step 4:
    Figure 4. Start the installation
    Start the installation
    Start the installation

    Figure 5. Installation

    Figure 6. Installation
  4. The default password is ZEND. The password is case sensitive. For this article, stick to using the default password.
    Figure 7. Enter password
    Enter password
    Enter password
  5. You know the product is installing once you see a screen similar to the Figure 8.
    Figure 8. Installation completes
    Installation completes
    Installation completes

Wait for a short while, and at the end of the installation, you are brought back to the i5/OS main menu. That indicates a successful install.

Then you can try accessing the Zend Core user interface from your Web browser using http://<ipaddress>:8000/ZendCore. <ipaddress> in this case refers to the IP address of the iSeries server. Log in using the ZEND password entered during installation of the product.

Figure 9. Login screen
Login screen
Login screen

If login is successful, you are taken into the Zend Core user interface. From this interface you can manage, monitor and test the server.

Under the Control Center menu, there are three main tabs:

  • From the System Overview tab, you can get information about the PHP version and Web server details as well as disk space information. You have the option of restarting the server from within this tab.
  • The PHPinfo tab displays information from the php.ini file.
  • The Benchmark tab provides functionality to benchmark a specific URL. You can retrieve details such as the duration of the test, total number of requests per second, and failed requests.

The Configuration menu allows you to configure values in the php.ini file, extensions and other Zend products. Lastly, the Documentation menu contains reference information along with search facilities for looking up the reference documents.

Figure 10. Zend Core user interface
Zend Core user interface
Zend Core user interface

However, if you are not able to see the login page, then check the following:

  • Ensure that the ZendCore HTTP Server on the iSeries has been started.
  • Check if port 8000 is already being used on the iSeries server. You can do so by running the NETSTAT command and choosing Option 3. If port 8000 is being used, you can open the /usr/local/Zend/apache2/conf/httpd.conf file and modify the following line:

Listen 8000


Listen <alternate_available_port>

Then, you need to open up the IBM Web Administration interface, and under the details for the ZendCore HTTP Server go to the Reverse Proxy tab. Amend all the Core configuration entries with the value of the <alternate_available_port>. Click Apply, and then click OK.

Figure 11. HTTP Web administration
Web administration
Web administration

Then restart the Zend Core server and try accessing the Zend Core user interface again using the following URL: http://<ipaddress>: <alternate_available_port>/ZendCore.

For this article, use the default port 8000.

Now, test a simple PHP script. Save the following into a file called hello.php under /usr/local/Zend/apache2/htdocs:

<title>PHP Test</title>
<?php echo '<p>Hello World: Trying out PHP on i5/OS</p>'; ?>

You can test this script from within a browser using this URL: http://<ipaddress>:<alternate_available_port>/hello.php. If you see output similar to Figure 12, then the Zend Core product is successfully helping to serve your PHP pages.

Figure 12. Results

A simple PHP script to connect to DB2 UDB for iSeries

If you were able to see the results as shown in Figure 12, you can continue toward writing a PHP script to access DB2 UDB for iSeries data. Before you begin, create the following table and insert some data into it.

create table QGPL.cust (custname char(15), custage integer, custcity char(20))
insert into QGPL.cust(custname, custage, custcity) values ('Suita' , 27, 'Kuala Lumpur')

Deploy and test the script

<table width="75%" border="1" cellspacing="1" cellpadding="1" bgcolor="#eeeeee">
<tr> <td><b>Customer Name</b></td> <td><b>Customer Age</b></td>
<td><b>Customer City</b></td> </tr>
//Establish connection to database
$host = "<RDB_name>";
$conn = db2_connect ($host,"<userid>", "<password>");
$query = "Select * from QGPL.cust";
//Execute query
$queryexe = db2_exec($conn, $query) ;
//Fetch results
print ("<b>The result of the query is:</b>\n");
while(db2_fetch_row($queryexe)) {
 $custname = db2_result($queryexe, 'CUSTNAME');
 $custage = db2_result($queryexe, 'CUSTAGE');
 $custcity = db2_result($queryexe, 'CUSTCITY');
//Put the results in an HTML table.
print("<tr bgcolor=#ffffff>\n");

The <RDB_Name> can be viewed by issuing the WRKRDBDIRE command. You can also view the RDB name from within the iSeries Navigator. Expand the iSeries machine you are working with and check under the Databases section. The <userid> and <password> can be a valid userid and password that has the authority to perform selects on the QGPL.cust table.

Save the above in a file called DB.php under /usr/local/Zend/apache2/htdocs directory and access it from your browser using this URL: http://<ipaddress>:<alternate_available_port>/DB.php

You should see the output as below:

Figure 13. Results


The aim of this article was to introduce deploying PHP scripts to access DB2 UDB for iSeries data using the Zend Core for i5/OS product. The simple steps provided should help you get started down the path to writing more complex PHP scripts to manipulate your DB2 UDB for iSeries data. ibm_db2 functions allow you to perform selects, prepared selects, inserts, updates, and deletes, to call stored procedures, and, among other operations, also retrieve metadata information for your database. For more details and sample codes on using all the ibm_db2 functions, refer to the Related topics section of this article.

Downloadable resources

Related topics


Sign in or register to add and subscribe to comments.

Zone=Information Management, Open source, IBM i
ArticleTitle=Use PHP scripts to access DB2 UDB for iSeries data with Zend Core for i5/OS