PHP Revisited

A look at the capabilities PHP open up on the IBM System i platform.

A look at the capabilities PHP open up on the IBM System i platform.

Several things have happened since our initial article on PHP, so we thought we'd bring you a brief update along with another example of why we're so excited by the capabilities PHP opens up to the IBM* System i* platform.

MySQL coming to System i

The latest news involves a joint announcement by IBM and MySQL that the two companies plan to offer the MySQL database on the System i platform. Since MySQL is arguably the most popular database in the PHP world, and it's the basis for the vast majority of available applications, this is an important story. We should point out that this is not to say that MySQL isn't already available on System i--it is. By following the instructions provided by IBM on the Zend developers forum, many people have successfully implemented it. However, this announcement was the first indication that an official version of MySQL would become available on the system, thus alleviating the worries of management who might be unsure about implementing non-IBM-supported software.

But that's not the exciting part--it was what was hinted at by the intriguing words "The two companies will work together … to deliver DB2* for i5/OS* as a certified MySQL storage engine." Hmm--interesting. Did that mean that DB2 would be the underlying data store for this new version of MySQL? And if so, would we be able to access our existing databases via MySQL and PHP? Perhaps even access the MySQL database via DB2 and (even better) native I/O? That would certainly offer some wonderful possibilities! Imagine being able to install one of the many PHP CRM applications and have it easily bridge with your existing applications. Or perhaps write reports based on MySQL data associated with a PHP Help Desk application using your existing RPG skills! These are exciting possibilities--so is that what we can look forward to?

According to Jim Herring, director of IBM System i products and business operations, that seems to be the direction IBM is heading. During the opening session at the recent COMMON conference in Anaheim, Herring was asked whether MySQL will be able to access existing DB2 databases and the answer was yes, this is indeed the intention.

Needless to say, it'll be a while before this comes to fruition, but it will comfort those fearful for the platform's survival that it's so firmly embracing not just Java* but also two of the Web world's other leading technologies--PHP and MySQL.

Experimenting with PHP

In our previous article, we mentioned that PHP was only planned for availability on V5R4 and suggested some options to let you "play" in the meantime. There are two significant changes on this front. First of all, Zend and IBM responded to requests from users and Business Partners and have made PHP available for V5R3 users. If that still doesn't help you because you don't have the authority to load PHP on your System i platform and management won't let you experiment with it, never fear, there's now another interesting "playground" offering.

In conjunction with IBM, Zend has now bundled a copy of PHP with DB2 Express and a fully configured version of Apache. Once installed, this lets you develop PHP applications on your PC and do everything you could do with the System i version except use the i5 toolkit extensions. This way you can develop and test a full DB2-based application that can switch simply and easily to your System i platform. You can link to the downloads for Windows* and Linux*, but note that this is a secure site and you will have to register with Zend as a developer before you can access it. There's no charge and it gives you access to a wealth of information. Happy playing!


A look at the capabilities PHP open up on the IBM System i platform.

A look at the capabilities PHP open up on the IBM System i platform.
Using Web Services in PHP

Web services are fast becoming a vital part of daily life in many System i shops, and the number is growing daily. While many people have had considerable success using tools such as Scott Klement's HTTP API, the lack of built-in support in RPG deters many others from trying their hands.

PHP, on the other hand, not only has built-in support for consuming Web services, but using this support is simplicity itself (for more detail, see "Integrating PHP Using Web Services"). Take a look at the following code sample. It uses two separate Web services--one to obtain a stock quote and the other to obtain the Canadian/US dollar exchange rate so that the value of the stock can be expressed in Canadian dollars. (After all, we are based in Canada!)

This code creates a Stock Quote SOAP Client by referencing the URL of the Web Services Description Language (WSDL) for the stock-quote service. Under the covers, PHP interrogates the WSDL file and determines how to invoke the referenced Web services, the requirements for the XML document that will describe the request and the format of the returned XML document. We neither need to know or care what these look like (although if you're interested you can see the contents of the WSDL by entering the URLs into a browser). PHP takes care of it all for us. All we need to know is the name of the method we wish to use (in this case "getQuote") and the parameter required (the stock symbol). We can glean this information from the WSDL itself or from the Web pages associated with the service. Once we have the stock-quote object, we can call the "getQuote" method to obtain the stock price.

Next, we follow a similar sequence to obtain the current Canada/US exchange rate. Once we have both values, we simply output the results to the browser. The result would look like this:

IBM price is $103.29 - that is $114.300714 in Cdn$

A total of five operations--if it got much simpler than that the code would write itself!

So, what are you waiting for? Go download PHP and start experimenting--you'll be amazed at what you can do. The System i platform, PHP, DB2, MySQL and RPG IV --what an incredible combination!