Zend Core for IBM - A guided tour for PHP developers

Getting started with PHP and IBM Cloudscape and DB2 on Linux

Have you considered setting up a PHP 5 on your Linux™ server, but not had the time to learn how? This article will help guide you through the installation of a PHP 5 environment using the industry's first integrated PHP environment that includes the IBM® Cloudscape™ database server. Installation and configuration is greatly simplified using Zend Core for IBM compared to setting up a complete development and deployment environment from scratch. Zend Core for IBM also provides commonly used PHP extensions and DB2® client libraries to get you connected to your DB2 Universal Database™ (UDB) servers. Support for Zend Core is available from Zend Technologies, a leading provider of PHP products and services, but it is a free download and a time saver for any PHP developer who wants to build web applications for IBM Cloudscape or DB2 UDB.


Grant Hutchison (ghutchis@ca.ibm.com), Product Manager, Cloudscape and IBM Database Developer Initiatives, IBM Toronto Lab

Author photoGrant Hutchison is a Product Manager responsible for supporting the application development community for IBM database servers including DB2 UDB and Cloudscape. Grant has a graduate degree in Software Engineering and he has held various technical and management roles in the IBM Toronto lab over the past 13 years.

Stewart Nickolas (nickolas@us.ibm.com), Emerging Technologies, IBM, Software Group

Author photoStewart Nickolas has worked in the Emerging Technologies group in IBM for the past five years during which he has worked on Web services, Eclipse based tools for Web services and rich Internet client technologies.

14 July 2005

Also available in Russian Japanese

Introducing Zend Core for IBM

Zend Core for IBM is a product that has been jointly designed and developed by IBM and Zend Technologies. The product includes binary version of PHP 5 for various platforms including AIX® and Linux. The product also bundles the IBM Cloudscape database server, which is a commerically distributed version of the Apache Derby database server, and DB2 UDB Version 8.2 Runtime Clients to support the development and deployment of web applications. Zend Core includes many useful PHP language extensions also such as:

  • ibm_db2 - New native PHP extension for IBM DB2 UDB servers and IBM Cloudscape
  • simplexml - SimpleXML extension provides a very simple and easily usable toolset to convert XML to an object
  • many more...

What about documentation?

There are currently two guides available for Zend Core for IBM.

  • Zend Core User Guide
  • Zend Core Installation and Maintenance Guide

Both of these guides are available as PDF files at http://www.zend.com/core/network/resources.php

Installing on Linux (x86)

It is important to download the proper binary version of Zend Core for IBM for the operating platform you are using. In this example we are using a Linux x86 distribution, namely the Novell's SUSE LINUX Enterprise Server 9 distribution. The file you download will likely be named something like this: ZendCoreForIBM-v1.1.1-Linux-x86.tar.gz.

There are a few pre-requisites that should be considered before attempting an installation of Zend Core for IBM. The supported Web Servers are Apache 1.3.x (compiled in prefork mode only) and Apache 2.0.x (compiled in prefork mode only).

Currently supported operating environments for Zend Core for IBM include:

  • Linux (x86 and x86_64)
  • Linux on POWER
  • IBM AIX v5.2 and later

Zend Core for IBM includes an Administration console as a web application. The supported browsers include:

  • Microsoft® Internet Explorer 5.5 and above (on Windows™ of course)
  • Netscape 7 and above
  • Mozilla 1.7 and above
  • Firefox 1.0 and above (this is the browser used by the authors)
Listing 1. Installation steps for Linux
Unpack the product files in a temporary directory
$ tar -xzvf ZendCoreForIBM-v1.1.1-Linux-x86.tar.gz
$ cd ZendCoreForIBM-v1.1.1-Linux-x86
Start the graphical Zend Core for IBM installer (as root) 
$ ./install
(or) Start the tty-based Zend Core for IBM installer (as root)
$ ./install-tty

After you accept the license terms, 
you will be asked to specify the default installation directory
(default location - this can be changed during installation)

Set a password for the Zend Core Web based administration tool

Setup you Zend Core Network User ID and Password.
You will be given the option of when the Zend Core 
updater will check each day for updates.

Install the IBM DB2 UDB Runtime Client Version 8.2 
This step will ask the following 
(defaults are shown, but can be changed):

DB2 client instance user name (db2inst1)
DB2 client instance group name (db2iadm1)
DB2 client instance home directory (/home/db2inst1)
Password for DB2 client instance user (user-defined)

Install IBM Cloudscape v10 (yes/no)

(optional - but recommended)
Specify the location of your Web Server, 
if you have an Apache 1.3.x or 2.x Web Server 
already installed it will be detected.
In the installation the Apache 2.0.49 web server is 
installed from the SLES 9 installation CDs. 
YAST is used to install Apache and its 
related packages (apache2-prefork, apache2-worker, 
libapr0 - Apache Portable Runtime Library).

The installer will then ask which installation method 
should be used to enable PHP for your Web Server.
The options include: Apache module, FastCGI, CGI 
(Apache module is the recommended method).

Finally, the installer will ask you to select a virutal 
server to run the Zend Core for IBM Web Administration console.

NOTE: If you plan to build and deploy PHP applications with Cloudscape you will need to install the IBM DB2 UDB Runtime Client along with IBM Cloudscape v10.

Verifying the installation

To verify the installation, ensure the Web Server is started and then open a supported browser with the following URL (http://localhost/ZendCore). Of course, you will likely have a proper host name and port setup as a virtual server for your environment.

Figure 1. Zend Core for IBM - Login screen
Zend Core for IBM - Login screen

Deploying a PHP application using IBM Cloudscape

The web based Zend Core for IBM console provides an easy to use interface to interact with the Cloudscape Network Server.

Starting and stopping Cloudscape

Start the web server which you installed Zend Core for IBM onto and login to the Control Center (for example: http://localhost/ZendCore). Select the following Configuration->Cloudscape tabs from the console and Start the Cloudscape server.

Figure 2. Zend Core for IBM - Cloudscape Network Server Administration
Zend Core for IBM - Cloudscape Network Server Administration

You can always verify the installed components (and there versions) included with Zend Core for IBM from the graphical web administration console. Control Center->Updates tabs

Figure 3. Zend Core for IBM - Verify components
Zend Core for IBM - Verify components

A shell script is also provided to start and stop the Cloudscape Network Server database. The shell script is located in the installation directory, for example /usr/local/Zend/Core/sbin

  • cloudscape.rc {start|stop|restart}

The default port for Cloudscape in network server mode is 1527, this is important when connecting to a Cloudscape database used in the connection URL.

Creating a Cloudscape database

The easiest way to create a Cloudscape database is to use the create_cloudscape_database.sh shell script located in the /Zend/Core/sbin directory in the Zend Core for IBM installation directory.

create_cloudscape_database.sh -d database name [-h host] [-n port] [-u user] [-p password]

The database name is the only required parameter the others default to the following:

  • -h (localhost)
  • -p (1527)
  • -u (admin)
  • -p (admin)

Note: Ensure the Cloudscape Network Server is running before attempting to create a Cloudscape database.

The command to create a Cloudscape database called hello would look like the following:

create_cloudscape_database.sh -d hello

Also note that the hello database is physically created in the following directory: /usr/local/Zend/Core/var/cloudscape/hello.

Drop (delete) a Cloudscape database by removing the directory and all its contents, including subdirectories.

One of the many nice features of Cloudscape is that its databases are platform independent and therefore you can simply move an existing Cloudscape database into your Zend Core environment by moving the database into the appropriate directory.

Populating a Cloudscape database

Once you've created your database you can populate it with data using either the Cloudscape ij scripting tool or simply use the DB2 native interface for creating tables and adding data.

ij is Cloudscape's interactive scripting tool. It is a simple utility for running scripts against a Cloudscape database. ij is a Java application, which you start from a command window.

Let's connect to the hello database and create and populate a table called customer_data.

#cd /usr/local/Zend/Core/var/cloudscape/hello

ij version 10.0

Next you'll need to instruct ij to use the embedded driver by using the following ij command:

ij>driver 'org.apache.derby.jdbc.EmbeddedDriver';

Next connect to the database by issuing a connect command.

ij>connect 'hello;user=admin;password=admin;';

ij can be used to execute SQL script files. Next create a new file called hello.sql.

Content of the file hello.sql

create table customer_data (
customer_id int NOT NULL,
first_name varchar(50),
last_name varchar(50),
address varchar(50),
PRIMARY KEY (customer_id)

Now execute the script.

ij>run 'hello.sql';

ij>insert into customer_data values (1, 'Hello', 'World', 'World Address');

ij>insert into customer_data values (2, 'Stewart', 'Nickolas', 'United States of America');

ij>insert into customer_data values (3, 'Grant', 'Hutchison', 'Canada');

Finally, to exit ij, type 'exit'

Congratulations, you have created a Cloudscape database and populated a table with a row of data. Now, you can pull together a simple PHP application to view the data from a browser.

Testing connectivity

Now that we have a Cloudscape database created and populated with some sample data the next task is to use the IBM DB2, Cloudscape and Apache Derby Functions available as the ibm_db2 extension for PHP. Native DB2 PHP Driver to connect to the database and retrieve data.

There are two ways of obtaining a connection to the Cloudscape database that we created: cataloged and uncataloged conenctions.
Use the db2_connect() API to connect using an uncataloged Cloudscape database connection. For more information on the difference between cataloged and uncataloged databases please consult the Zend Core for IBM Documentation (http://localhost/ZendCore/index.php?frame=documentation).

Figure 4. Zend Core for IBM - Online documentation
Zend Core for IBM - Online Documentation

Before writing a PHP script file, using the Native DB2 and Cloudscape PHP extension, first ensure that the extension has been activated within our PHP environment. Zend Core for IBM provides a graphical administrative interface to verify language extensions. The following Figure notes that the ibm_db2 has been installed and is currently active. Active language extensions will be shown as a green indicator.

Figure 5. Zend Core for IBM - PHP extensions
Zend Core for IBM - PHP extensions

You should now be ready to develop and deploy your PHP web application. Copy the code in listing 2 into the appropriate htdocs directory for your web application server.

Listing 2. Testing the Cloudscape PHP web application (hello.php)

$database = "hello";
$hostname = "localhost";
$port = 1527;
$user = "admin";
$password = "admin";

$conn_string = "DRIVER={IBM DB2 ODBC DRIVER};DATABASE=$database;";
$conn_string .= "HOSTNAME=$hostname;PORT=$port;PROTOCOL=TCPIP;";
$conn_string .= "UID=$user;PWD=$password;";

try {
    $conn = db2_connect($conn_string, '', '');
    if (! $conn) {
         echo db2_conn_errormsg();
    } else {
      $result = db2_exec($conn, "select * from customer_data");
         if ($result) {
           while ($row = db2_fetch_both($result)) {
             echo "Hello, ".$row[1]." ".$row[2]."
"; } } db2_close($conn); } } catch (Exception $ex) { echo $ex; } ?>

Completed PHP solution

We now have a complete PHP web application that has been fully implemented using the Zend Core for IBM product using the embedded database server, IBM Cloudscape.

Figure 6 'Hello World' PHP database application using Cloudscape
PHP database application using Cloudscape


We hope that you have enjoyed a quick tour of the new Zend Core for IBM product !! Cloudscape is usually only used for deploying Java applications including: standalone, client/server, or web-based applications. It is possible to develop and deploy PHP web applications using a Java database server like Cloudscape.
If you require additional scalability and more advanced database server features you can deploy the same PHP applications (with very minor changes) to use a DB2 UDB server instead. DB2 UDB servers are available on many different platforms including: iSeries™, z/OS®, Linux, UNIX, and Windows. The PHP development community continues to grow and the language itself evolves through community-based innovation. If you encounter any road bumps on your path to deploying applications using Zend Core for IBM you can obtain support directly from Zend.

Note that there are many additional features and capabilites in Zend Core for IBM and the new Native DB2 and Cloudscape extension for PHP that we were unable to cover completely in this introductory article.



developerWorks: Sign in

Required fields are indicated with an asterisk (*).

Need an IBM ID?
Forgot your IBM ID?

Forgot your password?
Change your password

By clicking Submit, you agree to the developerWorks terms of use.


The first time you sign into developerWorks, a profile is created for you. Information in your profile (your name, country/region, and company name) is displayed to the public and will accompany any content you post, unless you opt to hide your company name. You may update your IBM account at any time.

All information submitted is secure.

Choose your display name

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerWorks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

Required fields are indicated with an asterisk (*).

(Must be between 3 – 31 characters.)

By clicking Submit, you agree to the developerWorks terms of use.


All information submitted is secure.

Dig deeper into Information management on developerWorks

Zone=Information Management
ArticleTitle=Zend Core for IBM - A guided tour for PHP developers