Thursday, July 15, 2010

Sample code in Zend Server, Woohoo!

I work remote. You may work remote too. But as I was planning a trip to the corporate HQ I was asked to provide remedial IBM i training to some of our newer account reps. And the subject of the Samples directory came up. I know what you are thinking, yet another gratuitous post about Zend Server for IBM i, right? Of course it is. But this is beneficial to both paying and non-paying customers alike.

The samples directory that ships in the document root of Zend Server for IBM i has something that any company looking to explore PHP would like to see: free code! I have said several times that Zend Server for IBM i addresses many, not all, of the issues that IBM i shops have encountered. We fixed, enhanced or added a bunch of stuff to the product and the repose from those who have taken the plunge is overwhelmingly positive. The Samples directory addresses yet one more question raised by many an IBM i shop looking to explore PHP: How do I show my boss a PHP script running on MY machine? Lets’ explore each of the scripts available and how you can leverage them for your needs.


First let’s discuss the welcome page. Once you have Zend Server for IBM i installed and you start the Admin Interface (http://youribminamehere:10088/ZendServer) you are presented with a welcome screen. The screen lists 8 things that help you to learn PHP for IBM i. Option number 8 talks about the samples and all you need to do to see and run the sample code is click that link. Each has two links. The first runs the script and show the output. The second shows you the code that makes up the script. But if you have Zend Studio for IBM i handy you open up the Samples directory in the document root of your Zend Server instance.

I won’t go into boring detail about each of the scripts but it may be helpful to know that there are six examples. Hello World, SQL Access, SQL Access using Zend Framework, SQL Access to MySQL, Program Call and LDAP example. Let’s discuss the SQL Access script in more detail as that is my biggest requests: How do I show my boss some of our data in the web using PHP?
The SQL access example is no glamorous. But it does the necessary heavy lifting of going to a library on the IBM i, getting some data from a physical file and displaying it in an HTML table. The file in the example, SP_CUST, is located in the library ZENDSVR. This file contains several columns which are all requested via the SQL statement in the code example. Only customers with a customer ID greater than 1220 are selected from the database. Then, as the resultant data set is processed, each record is formatted to load into an HTML table. There are examples of error control and basic PHP and database control. A nice script for newbies.

For those of you who are adventurous, you can copy this script and modify it to display some of your very own data. There are only two changes you would really need to make. The first is in the SQL statement where you would create your own select option. The second is in the bind statement as you can omit or alter the lower-limit selection of the SQL statement. The rest of the code will generate the HTML table automatically. Please copy the PHP code and then modify it. Don’t destroy the original as you may want to get back to it at some point.

Well, I hope this helps a few of you who are thinking about kicking the tires of PHP. Like many other aspects of the PHP experience on IBM i, there is no charge for this feature. But if you are interested and having fun, I encourage you to take the next step and play some more. Maybe get a little education at Zend or SystemiNetwork. We’d love to see you there!