Before you start
This tutorial is aimed at Web application developers who want to develop database-driven applications that are powered by an IBM DB2 pureXML database. The reader should be familiar with basic PHP code and be able to work with the Windows command prompt in order to follow the tutorial. Some experience with database management systems and the SQL language is also required. By the end of this tutorial, you will learn how to create object-oriented PHP Web applications that take advantage of a pureXML database.
IBM DB2 Express-C includes pureXML, a way to store XML data natively in a relational database table. pureXML allows the user to query, index, and manipulate this XML data. You can use a series of functions to work with a hybrid of relational and XML-based data in a seamless fashion. This enables the development of applications that utilize the strengths of both traditional relational database tables and XML data.
XML is now widely used as a portable data storage format, and you will frequently find public data and Web services providing access to their data in XML format. By using IBM DB2 Express-C you can develop applications that load this XML data directly into the database, and create applications that are driven by this data without having to convert it into relational columns. Of course, sometimes it makes sense to take this data and convert it, and in this tutorial you will see a mix of various techniques for working with XML in DB2.
In this tutorial, you will learn how to create an alerts system that polls the Euro foreign exchange rates from the European Central Bank Web site on a daily basis. If a new set of rates are found, the application will load this data into a DB2 database, and it will also send an alert in two ways: as a Google Talk (XMPP) instant message, and as an SMS text message to a cell phone. You will also learn how to import bulk XML data into a DB2 database, and in this case, you will load the entire history of Euro foreign exchange rates, dating all the way back to 1999, when the Euro currency was first introduced. Later in the tutorial, you will develop a PHP script that generates a chart of the maximum exchange rates for each month of the current year.
To follow the steps in this tutorial, you will need to install the following software:
- IBM DB2 Express-C 9.5
- PHP 5.2
- XMPPHP library
See Resources for the links to the download sites and to articles that walk you through the installation and configuration of the above software.
This tutorial assumes that you store all of the source code in the folder C:\currency. If you have not already done so, create this folder now by opening Windows® Explorer and navigating to the root of the C: drive. In there, right-click and choose New>Folder. Name the folder currency. Alternatively, download the source code for this tutorial and extract the folder to your C: drive.
You need to make some changes to your PHP configuration file to follow this tutorial. In php.ini locate the line that reads something like
error_reporting = E_ALL and change it to:
error_reporting = E_ERROR.
Next, find the line similar to:
display_errors = On and
change it to read:
display_errors = Off. Finally, scroll
down the file until you find the section for PHP extensions. Many of these extensions
will be disabled by default, with a semi-colon at the start of the line commenting out this particular feature. To enable features, simply remove the semi-colon at the start of the line. Now, find these lines in Listing 1 and make sure the semi-colon (;) at the beginning of each is removed.
Listing 1. Removing the semi-colons
extension = php_curl.dll extension = php_gd2.dll extension = php_mbstring.dll extension = php_openssl.dll extension = php_sockets.dll