Skip to main content

skip to main content

developerWorks  >  Information Management | Open source  >

Use PHP on System i, Part 2: Net.Data and PHP

A comparative study

developerWorks
Document options

Document options requiring JavaScript are not displayed


Rate this page

Help us improve this content


Level: Intermediate

Margaret Myslinska, Software Engineer Intern, IBM
Andrew Nere, Software Engineer Intern, IBM
David Swenson, Software Engineer Intern, IBM
Gloria Velazquez, Software Engineer Intern, IBM
Kathryn Lamont (kathrynl@us.ibm.com), Software Engineer, IBM
David Peraza (dperaza@us.ibm.com), Software Engineer, IBM

13 Feb 2007

Compare PHP with the Net.Data server-side scripting language, which IBM develops with DB2®. Understand the origins of the languages, their syntax differences, usage learning curves, database connections, and other differences. This article is the second part of a series based on working with PHP on System i™.

Introduction

On April 3, 2006, IBM® and Zend Technologies Ltd. began to bring the hypertext preprocessor (PHP) engine and PHP development tools to the System i platform. PHP is popular in the open source community because of its capability to create dynamic Web applications. The PHP open source community has developed literally thousands of PHP applications for many different uses. System i customers can be excited about the number of applications and capabilities that this emerging technology brings to the business world.

This article is the second part of the IBM PHP Speed Team's experience in the summer of 2006 working with PHP on the IBM System i platform. The goals for the team included the following:

  • To attain hands-on experience with PHP on the System i.
  • To gain insight into PHP through the use of PHP applications.
  • To port PHP applications from MySQL to DB2.

Part 1 of the series provided an overview of PHP on System i, showed how to install PHP and DB2 on System i, and showed how to port a MySQL application to DB2 on i5/OS®. This article compares the scripting languages of PHP and Net.Data on System i hardware, specifically on i5/OS. It focuses on the origins of the languages, differences in syntax, learning curves of each language, database connections for each, and other uses for each language. Code listings 1 through 6 represent segments of an example program that populates and displays tables: one version created in PHP and the other version in Net.Data. This article includes a performance comparison of the two versions of each program.



Back to top


High-level comparison of the languages

This is a very general comparison of the PHP and Net.Data server-side languages, including their relative popularity, the platforms they support, and development environments, followed by a more in-depth look at the differences (and similarities) in the syntax of the languages.

Language origins

PHP is one of the most widely used Web programming languages. PHP is a powerful server-side scripting language that you can use to create dynamic Web sites and applications. PHP began as Personal Home Page, a simple Perl hack that Rasmus Lerdorf wrote in 1994. Today, PHP has come to mean PHP: Hypertext Preprocessor. In 1997, Zeeve Suraski and Andi Gutmans produced PHP 3. Shortly afterwards, they created Zend Technologies, the company that produces the Zend Engine for PHP.

On July 13, 2004, PHP 5 was released. Before this, PHP 3 saw the introduction of object-oriented function to the language. PHP 4 added the ability to pass and return by reference. The object-oriented function was rewritten for PHP 5, allowing for better performance with more function and features.

Net.Data is also a server-side scripting language that extends Web servers by enabling the dynamic generation of Web pages. The origins of Net.Data come from the Web macro capability of the DB2 WWW Connection from the IBM Santa Teresa Lab. The DB2 WWW Connection was first released on OS/2® and AIX® in November 1995. By its second release in July of 1996, the tool was renamed Net.Data and was available in a beta for both systems. Later that year, it was made available on the AS/400® (which became System i) with OS/400® V3R7 and also ported back to V3R2.

One of the crowning moments of Net.Data was its use in the creation of the dynamic Web pages of the 1998 Winter Olympics at Nagano. The Nagano Olympics Web site experienced nearly 650 million hits during the 16-day event, reaching a peak volume of 110,414 hits per minute.

The data for these dynamic Web applications come from relational and nonrelational database management systems, such as DB2, other Distributed Relational Database Architecture (DRDA) databases, and flat-file databases. You can rapidly build Net.Data applications using a scripting language that is simple, yet powerful.

Popularity

PHP has become one of the most widely used Web programming languages. With over 4.5 million PHP developers and over 22 million Internet domains using PHP, you can see the popularity of this technology. Literally thousands of PHP applications exist, many of which are open source. They can be downloaded, used, and modified freely. Shopping carts, bulletin boards, and wikis are all popular uses of this powerful language.

While Net.Data is not nearly as common as PHP, it is very popular among IBM customers, especially those that use the System i platform and i5/OS. Businesses can get their data on the Web without a lot of education and resources. No specific numbers are available on the number of Net.Data developers.

Platforms supported

PHP is platform independent, which means it works with a wide range of operating systems. Net.Data is also designed to be a cross-platform language. Net.Data has been available for many years on a variety of platforms, including Windows NT®, AIX, HP-UX, Linux®, Sun Solaris, OS/390®, and i5/OS. IBM currently supports Net.Data only on the i5/OS and OS/390 platforms, because IBM stopped supporting the other platforms in 2004.

Development environments

You can develop PHP applications in several different environments. You can use general editing tools, such as Notepad and other text editors, many of which recognize PHP syntax. Zend Studio is an IDE specifically created for PHP development, and it is available on the Zend Web site (see Resources) for System i customers. No specific development environments exist for Net.Data. You can develop Net.Data applications in Notepad and other text editors.



Back to top


Syntax of the languages

All PHP code begins and ends with a PHP tag (for example, <?php echo 'Hello'; ?>). Each line in PHP ends with a semicolon, similar to the C language. This distinguishes one set of instructions from the next. White space is ignored between PHP statements.

The Net.Data macro language has only a few rules about programming format. This simplicity provides programmers with freedom and flexibility. A single instruction can span many lines, or multiple instructions can be entered on a single line. Instructions can begin in any column. Spaces or entire lines can be skipped. You can use comments anywhere.

Use of variables

In PHP, all variables, except defined constants, must begin with a $. After the $, all variables names must begin with either an underscore or a letter. All variables are case sensitive. Variables in PHP are weakly typed: you can assign a variable as an integer and later as a character. Variables are always assigned by value, which means that when one variable is set equal to another variable, they are then independent of each other. In order to assign by reference, use an &. Math and logic operators are handled in PHP the same way they are in the C language.

PHP also has automatic type conversion for arithmetic operations. If any of the operands is a float, then all operands are evaluated as floats, and the results are floats. Otherwise, the operands are interpreted as integers, and the result is also an integer. The programmer does not usually set the type of a variable; PHP determines the type at runtime, depending on the context in which that variable is used. Supported variables include integers, floating point numbers, strings, arrays, and objects.

In Net.Data, as in PHP, variables start with an underscore or letter, and they are case sensitive. Net.Data regards all data as character strings. Content of the variables can change, as with PHP. However, Net.Data does not determine at runtime what each character type is. Because all character data is a string, Net.Data uses built-in function to perform arithmetic operations on a string that represents a valid number, including those in exponential formats.

Net.Data has three types of variables as follows:

  • Variables specifically defined by the user using the %DEFINE statement (define in PHP).
  • Variables that Net.Data predefines and makes available.
  • Variables that are a part of a %FUNCTION block, and they can only to be referenced within that block

There are five types of scope that these three types of variables can have, depending on how and where they are declared:

  • Global
  • Macro file
  • Function block
  • Report block
  • Row block

Learning curve

PHP is easy to learn. The syntax of PHP is similar to that of the Java™, C, and Perl languages, so programmers who know these languages can be very comfortable with PHP. Math and logic operators are handled in PHP the same way as they are in the C language.

The Net.Data scripting language is easy to learn and allows the use of existing skills to rapidly develop Web applications. Net.Data is a favorite of many IBM customers because of its easy learning curve.



Back to top


Databases

A side-by-side comparison of the database use of PHP and Net.Data illustrates the features of each, such as database connections, SQL syntax, and performance considerations.

Connection to database

PHP can connect to multiple database systems, including PostgreSQL, MySQL, Access, and DB2. Connection to the IBM DB2 database can use either the Open Database Connectivity (ODBC) driver or the IBM_DB2 connection driver. The ODBC driver is slightly older than IBM DB2 driver, but because ODBC is not always used specifically for the DB2 database, open source applications use it more often.

Net.Data can connect to relational and non-relational database management systems, such as DB2 and DRDA databases. DRDA is an industry standard, which IBM initiated and The Open Group supports, for accessing database information across IBM platforms. DRDA follows SQL standards. Net.Data can also connect to the DB2 database using the ODBC connection.

DB2 database connection

There are many differences between PHP and Net.Data when connecting to DB2. PHP has two main drivers available: ODBC and IBM_DB2. Net.Data has one interface to DB2 for i5/OS. The PHP example in this article uses the IBM_DB2 driver. The IBM_DB2 drivers are specific to the DB2 database, and they might relieve some historic connectivity issues with ODBC. IBM_DB2 Connect implements the DRDA architecture to reduce the complexity and cost of accessing data stored in the DB2 database.

With PHP, use the db2_connect() function to connect to DB2 with the parameters shown in Listing 1. Once the link is successfully connected, DB2 returns a connection handle resource that remains active until it is closed using the db2_close() function. To show SQL statements in PHP, use the echo() function for each statement.


Listing 1. PHP connection to DB2 using IBM_DB2
                
$i5user =  strtoupper($i5user);	
i5host = strtoupper($i5database);	
$i5link = db2_connect($i5host, $i5user, $i5password, array("i5_commit" => 
						 B2_I5_TXN_READ_COMMITTED, 
                          'autocommit' => DB2_AUTOCOMMIT_OFF));
if (!$i5link) die('Failed connect: ' . db2_conn_error()." : ".db2_conn_errormsg());


With Net.Data the connection is done differently. Define a DATABASE variable initially within the macro to tell it which database to connect to. After the macro is interpreted, the connection is active and ready to execute SQL statements (see Listing 2). Displaying an SQL statement in Net.Data is as simple as defining SHOWSQL = "YES".


Listing 2. Net.Data connection to DB2
                
%DEFINE {
        DATABASE       = "D1092546"
        TABLE                = "SHAZAM.NETTABLE"
%}


Execution of SQL statements

In PHP, SQL statements are run using either the db2_exec() or db2_execute() commands. The two commands are similar in that they both run an SQL query; however, the results they return differ greatly. The db2_execute() statement returns true or false when completed, and the result set of the query must be bound to a variable before the SQL statement is run. With db2_exec(), the result of a successful query is a statement resource that contains all of the requested data; an unsuccessful query returns false. Listing 3 shows how PHP implements the db2_exec() command. The connection handle resource given when creating a database connection is a necessary parameter, along with the query that needs to be run. Listing 3 shows the db2_exec() command inserted to a table using a nested for loop.


Listing 3. PHP SQL execution
                
//Insert Data
	$data[0] = "INSERT INTO $schema.$table (SUBCAT, PRDNAM) VALUES ('HJ', 'WINTER')";
	$data[1] = "INSERT INTO $schema.$table (SUBCAT, PRDNAM) VALUES ('GT', 'HAHAHA')";
	$data[2] = "INSERT INTO $schema.$table (SUBCAT, PRDNAM) VALUES ('QW', 'SUMMER')";
	$data[3] = "INSERT INTO $schema.$table (SUBCAT, PRDNAM) VALUES ('AB', 'GOOD')";
	$data[4] = "INSERT INTO $schema.$table (SUBCAT, PRDNAM) VALUES ('HF', 'SPRING')";
	$data[5] = "INSERT INTO $schema.$table (SUBCAT, PRDNAM) VALUES ('SK', 'FALL')";
		
	for($j=0; $j<40; $j++) {
	    for($i=0; $i<count($data); $i++){
                @db2_exec($i5link, $data[$i]) or die('Failed 
					insert: ' . db2_stmt_error().":".db2_stmt_errormsg());
	    }
	}
	
//Committing insert	
	db2_commit($i5link);	
		
// Execute Query
	$query = "SELECT cat, subcat, prdnam
	   		  FROM $schema.$table
	     	  order by cat, subcat, prdnam
	   	      for fetch only";
	$result = db2_exec($i5link, $query);


By comparison, Net.Data requires a function to be created using the DTW_SQL language environment. This converts the character string contained within or passed into the function to a correct SQL statement. After it is converted, the SQL statement is run, and the results are returned from the function. The %MACRO_FUNCTION of Listing 4 shows six insert statements executed 40 times using a while loop.


Listing 4. Net.Data execution of SQL statements
                
%MESSAGE {
	default : { <p align="center"><font color="red"><b>
	$(DTW_DEFAULT_MESSAGE)....</b></font></p> %} : continue
%}

%FUNCTION(DTW_SQL) execSql(sqlstmt) {
   $(sqlstmt)
%}

%MACRO_FUNCTION crtTables() {
   @DTW_ASSIGN(COUNT, "1")
   @DTW_ASSIGN(END, "40")
   %WHILE ( COUNT <= END ) {
     @execSql("INSERT INTO $(schema).$(table) (SUBCAT, PRDNAM) VALUES ('HJ', 'WINTER')")
     @execSql("INSERT INTO $(schema).$(table) (SUBCAT, PRDNAM) VALUES ('GT', 'HAHAHA')")
     @execSql("INSERT INTO $(schema).$(table) (SUBCAT, PRDNAM) VALUES ('QW', 'SUMMER')")
     @execSql("INSERT INTO $(schema).$(table) (SUBCAT, PRDNAM) VALUES ('AB', 'GOOD')")
     @execSql("INSERT INTO $(schema).$(table) (SUBCAT, PRDNAM) VALUES ('HF', 'SPRING')")
     @execSql("INSERT INTO $(schema).$(table) (SUBCAT, PRDNAM) VALUES ('SK', 'FALL')")
     @DTW_ADD(COUNT, "1", COUNT)
   %}
%}

%FUNCTION(DTW_SQL) getinv() {
   SELECT cat, subcat, prdnam
   FROM $(schema).$(table)
   order by cat, subcat, prdnam
   for fetch only
%}


Note that all snippets of code in this article are portions of the same program used to create and populate a table in both PHP and Net.Data. Therefore, you need to create a table before running this code. Here is the create statement:


Listing 5. Table create statement
                

CREATE TABLE SCHEMA.TABLENAME 
      (CAT INT NOT NULL GENERATED ALWAYS AS IDENTITY(START WITH 1  
          INCREMENT BY 1), 
      SUBCAT varchar(15) NOT NULL, 
      PRDNAM varchar(25) NOT NULL);
      
 ALTER TABLE SCHEMA.TABLENAME ADD CONSTRAINT
      SCHEMA.CONSTRAINTNAME PRIMARY KEY (CAT);

Output results

Outputting the result set using PHP is slightly more complicated than using Net.Data. PHP requires the use of two or more IBM_DB2 functions to extract the rows and fields out of the results set. In Listing 6, db2_fetch_row() and db2_result() are used to extract the data from the statement resource. The db2_fetch_row() is used to iterate through the statement resource returning true until there are no more rows in the resource. On each iteration, db2_result() gets the value for each field within the row. Then formatting the output of the data is a matter of either using the printf() function, which is similar to C/C++, or using proper HTML table tags. In Net.Data, the data are either outputted directly from the query results or are assigned to a table using @DTW_ASSIGN(DTW_HTML_TABLE,"YES") (see Listing 7). There is no need to use HTML or other tags to format the output because Net.Data handles all the basic formatting. Another way to format in Net.Data is to generate an SQL report.


Listing 6. PHP SQL results output
                
// Output Query
	if ( $_POST["submit"] == "NO TABLES" ) {
	    global $result, $query;
		
	    echo '
	        <FORM action="DBExampleNetComp.php" method="POST">
		<input type=hidden name=method value=createTable>
		<input type="submit" name="submit" value="TABLES" />
	        </FORM><PRE>';
	    printf("%9s", "-----------------\n");
	    printf("|%s|%s|%s|\n", "CAT", "SUBCAT", "PRDNAM");
	    printf("%9s", "----------------\n");
	    while (db2_fetch_row($result)) {
	        printf("|%3s|%5s|%7s|\n", db2_result($result, 0), db2_result($result, 1), 
					db2_result($result, 2) );
	        printf("%9s", "-----------------\n");
	    }
	    echo '<PRE>';
	    list($totalSeconds, $extraMilliseconds) = timeAndMilliseconds();
	    fwrite($resultFile, "[" . date('Y-m-d H:i:s') . "] - No Tables: Start 
				Time: ;" . $startTime . 
                      ".; - End Time: ;" . date("H:i:s",
							   $totalSeconds) . ".$extraMilliseconds.;\n");
	}
	else {
	    global $result, $query;
		
	    echo '
	        <FORM action="DBExampleNetComp.php" method="POST">
		<input type=hidden name=method value=createTable>
		<input type="submit" name="submit" value="NO TABLES" />
	        </FORM><TABLE border=1><TR>
	        <TD>CAT</TD> <TD>SUBCAT</TD> 
					<TD>PRDNAM</TD> </TR>
	    ';
	    while (db2_fetch_row($result)) {
	         echo '<TR>';
	         echo '<TD>' . db2_result($result, 0) . '</TD>';
	         echo '<TD>' . db2_result($result, 1) . '</TD>';
	         echo '<TD>' . db2_result($result, 2) . '</TD>';
	         echo '</TR>';
	    }
	    echo "</TABLE>";
               }   



Listing 7. Net.Data SQL results output
                
/%HTML(main) {
  @DTW_ASSIGN(filename, $(fname))
  @DTWF_OPEN(filename, "a", "850")
  @DTW_TIME("X", STARTTIME)
  <HTML>
  <HEAD>
  <TITLE>Basic SQL Example</TITLE>
  </HEAD>

  <BODY bgcolor="white">
  <CENTER>
  <H1>Basic SQL Example</H1>
  <P><A HREF="/netdata/basic_sql.mac/table">Switch to Table format</A></P>
	
  @crtTables()
  @getinv()

  </CENTER>
  </BODY>
  </HTML>
  @DTW_TIME("X", ENDTIME)
	
  @DTWF_WRITEFILE(filename, "Start Time: ;$(STARTTIME);   --   End Time: ;$" . 
    "(ENDTIME); | ", "Y")
  @clrTables()
  @DTWF_CLOSE(filename)
%}

%HTML(table) {
  @DTW_ASSIGN(filename, $(fname))
  @DTWF_OPEN(filename, "a", "850")
  @DTW_TIME("X", STARTTIME)
  <HTML>
  <HEAD>
  <TITLE>Basic SQL Example</TITLE>
  </HEAD>
  <BODY bgcolor="white">
  <CENTER>
  <H1>Basic SQL Example</H1>
  <P><A HREF="/netdata/basic_sql.mac/main">Switch to Text format</A></P>

  @DTW_ASSIGN(DTW_HTML_TABLE,"YES")
  @crtTables()
  @getinv()
	
  </CENTER)
  </BODY>
  </HTML>
  @DTW_TIME("X", ENDTIME)
  @DTWF_WRITEFILE(filename, "Start Time: ;$(STARTTIME);   --   End Time: ;$" . 
    "(ENDTIME); | ", "Y")
  @clrTables()
  @DTWF_CLOSE(filename)
%}

Output of PHP and Net.Data

Figures 1 and 2 show the output of the PHP code, with and without tables. Figures 3 and 4 show the same output created using Net.Data. Note again that these outputs are the results of running the code snippets in the previous listings.


Figure 1. PHP output without tables
PHP output without tables

Figure 2. PHP output with tables
PHP output with tables

Figure 3. Net.Data output without tables
Net.Data output without tables

Figure 4. Net.Data output with tables
Net.Data output with tables

Database performance comparison

To compare the performance of database access from PHP and Net.Data scripts, the IBM PHP Speed Team created a workload using the previously described example. The team used the SilkPerformer tool to drive 10 concurrent users, each executing the same workload using unique tables for each user. The team recorded transaction times and throughput in transactions per second (TPS). The team then used the TPS data to compute the capacity of PHP relative to Net.Data by normalizing the TPS values of each run (TPS divided by TPSnet.data). The team also monitored system resources to ensure that there were no system bottlenecks, such as disk or memory constraints, and that the CPU was driven to 100%.

The team ran Net.Data first to establish a baseline. It is important to note that Net.Data runs SQL statements in-line in the Net.Data process that establishes the database connection. By contrast, with PHP, you can specify whether the SQL requests are run in-line in the PHP process (ZENDCOREAP jobs) or the SQL requests are submitted to run in server mode (processed by the QSQSRVR jobs). Another difference between Net.Data and PHP is that PHP can cache the prepared statements so that the prepare is done once, not each time a statement executes. Net.Data, on the other hand, supports only immediate execution, where the prepare is done each time a statement executes. To see how to change the source code in order to use prepared statements, refer to Listing 8. Listing 9 shows how to define the connection parameters so that the SQL statements run in-line. For direct comparison to Net.Data, the results in Figure 5 for the PHP environment use in-line SQL processing. As stated, PHP also supports server mode SQL processing, where the QSQSRVR host server jobs process the SQL requests. From a performance perspective, in-line SQL processing is better. However, if you need the SQL requests to be processed under unique user IDs with specific authorities, use server mode processing.


Listing 8. Preparing the insert statements
                
// Insert Data
   $data = array(
       array('HJ', 'WINTER'),
       array('GT', 'HAHAHA'),
       array('QW', 'SUMMER'),
       array('AB', 'GOOD'),
       array('HF', 'SPRING'),     array('SK', 'FALL') );
     
     $insert = "INSERT INTO $schema.$table (SUBCAT, PRDNAM) VALUES (?, ?)";
// Preparing insert statement     
     $stmt = db2_prepare($i5link, $insert);	
	
//Implements for Large Data group
    for($j=0; $j<40; $j++) {
        for($i=0; $i<count($data); $i++){
            @db2_execute($stmt, $data[$i]) or die('Failed 
					insert: ' . db2_stmt_error().":".db2_stmt_errormsg());		  
        }
    }
	
    db2_commit($i5link);


Listing 9. Connecting to DB2 with default parameters (running in-line)
                
 $i5link = db2_connect('', '', '', array("i5_commit" => DB2_I5_TXN_READ_COMMITTED, 
      'autocommit' => DB2_AUTOCOMMIT_OFF));
  if (!$i5link) die('Failed connect: ' . db2_conn_error()." : ".db2_conn_errormsg());



Figure 5. Performance results
Performance results

Note that the team used a database-intensive workload. In this case, significantly more PHP users can be supported than for Net.Data, especially if you employ the best practice of using prepared statements -- that is, preparing a statement once, not on each execute. The team used the latest available versions of Net.Data and PHP to obtain the data. The results are subject to change as both scripting languages evolve. Also, results listed here do not represent any particular customer environment. Actual performance can vary significantly from what the team experienced.



Back to top


Other uses and functions

You can use PHP and Net.Data for more than just direct database operation. The following sections describe the other uses of these languages.

Use with HTML

Because both Net.Data and PHP are often used to create Web sites and online applications, it is important that they can produce HTML, both static and dynamic. PHP is especially suited for Web development using HTML; you can embed PHP into the application using simple PHP tags. Listing 10 shows an example.


Listing 10. PHP embedded in HTML
                
 <html>
         <head>
                 <title>Hello World Example</title>
         </head>
         <body>
                 <?php
                   echo "Hello World!";
                 ?>
         </body>
 </html>


Embedded Net.Data in HTML is also fairly simple, but it requires the use of blocks, as shown in Listing 11.


Listing 11. Net.Data using HTML
                
%HTML(HelloWorld) {
  <html>
  <head><title>Hello world Example</title></head>

  <body>
  <P>Hello World! From HelloWorld
  </body>
  </html>
  %}



Including other files

You can include source files in an application using either PHP or Net.Data. You can create applications without writing all HTML and PHP or Net.Data in a single file. PHP uses the include function followed by the file path. Net.Data uses the function %INCLUDE followed by the file path enclosed in quotation marks.

Calling i5/OS commands and programs

Both PHP and Net.Data provide methods of calling external programs written in high-level programming languages, including COBOL, RPG, and C/C++. One method is to register the external program as a stored procedure and then use the SQL Call statement to run the program with a call to the stored procedure. The other method uses proprietary functions to run the external programs. PHP uses a set of three function calls, shown in Listing 12. First, use the i5_connect() function to connect to i5/OS, followed by the i5_progam_prepare() function to set up the program and parameters. Finally, call the program with the i5_program_call() function. Net.Data provides the function call %FUNCTION (DTW_DIRECTCALL) to call a program, as shown in Listing 13.


Listing 12. PHP program call
                
 //First, i5 connection must be established
 $conn = i5_connect("localhost". "userid". "password");
 if(!$conn) die("Failed connection");

 //If connected, prepare the program
 $prog = i5_program_prepare("PHP/PROGRAM". $other_params);

 //Finally, make the program call
 i5_program_call($prog, $params);



Listing 13. Net.Data program call
                
 
 %function(DTW_DIRECTCALL dc1() {
 %EXEC { /QSYS.LIB/NETDATA.LIB/MYPGM.PGM %}
 %}

To enable calling i5/OS system commands, PHP uses the set of two function calls shown in Listing 14. First, use the i5_connect() function to connect to the i5/OS, and then use the i5_command() function to make system calls to commands and APIs. To accomplish the same, Net.Data provides the DTW_SYSTEM command, shown in Listing 15.


Listing 14. PHP system call
                
//First, i5 connection must be established
 $conn = i5_connect("localhost". "userid". "password");
 if(!$conn) die("Failed connection");
 
 //If connected, make command call
 i5_command("COMMAND");



Listing 15. Net.Data system call
                
 %FUNCTION(DTW_SYSTEM) sys1() {
 %EXEC { /QSYS.LIB/ADDLIBLE.CMD LIB(MYLIBRARY) %}
 %}


Net.Data and PHP use each other

PHP and Net.Data can call each other. PHP and Net.Data applications can interact by passing parameters through a URL. Both languages are able to pass and receive parameters through the URL string. The PHP syntax is http://system:89/phpapp/test?parm1=somedata&parm2=somedata .

The Net.Data syntax is http://system:8090/nd/macro/test?parm1=somedata&parm2=somedata.

Support

Both PHP and Net.Data have official product support. Zend provides standard Internet support for three years for both the Zend Core and the Zend Studio Professional for i5/OS products. You can purchase Gold and Platinum phone support. IBM supports Net.Data for the i5/OS and OS/390 platforms only. Until September 30, 2004, IBM had supported Net.Data on HP-UX, Linux, and Windows NT.

You can also use unofficial online development support for both languages. You can find a formal PHP development manual available online at the PHP Web site (see Resources). The open source community maintains this manual, providing regular updates and additions. PHP users can help each other using a variety of forums and Web sites. There are many tutorials and beginner sites available for PHP and Net.Data users (see Resources).



Back to top


Conclusion

Net.Data has been a favorite of many System i customers in the past. It helped them create dynamic Web applications to use for business. With the availability of Zend's PHP products on i5/OS, PHP provides another scripting option to System i customers, with thousands of readily available open source applications. Both languages are easy to develop and use on the System i platform, with readily available support. System i customers have two great choices in dynamic Web application development.



Back to top


Acknowledgments

The authors wish to thank the following IBM experts for their contributions to this article:

  • Nadir Amra from the IBM Net.Data Developer Support Team
  • Charles Farrell from WebSphere Performance for System i
Share this...

digg Digg this story
del.icio.us Post to del.icio.us
Slashdot Slashdot it!



Resources

Learn

Get products and technologies
  • Go to the Zend Web site to download PHP for System i.

  • Build your next development project with IBM trial software for download directly from developerWorks.


Discuss


About the authors

Photo of Margaret Myslinska

Margaret Myslinska was an IBM Software Engineer Intern during the summer of 2006. She is currently finishing her degree at University of Chicago, Urbana Champaign, Illinois.


Photo of Andrew Nere

Andrew Nere was an IBM Software Engineer Intern during the summer of 2006. He is currently finishing his degree at St. Cloud State University, Minnesota.


Photo of David Swenson

David Swenson was an IBM Software Engineer Intern during the summer of 2006. He is currently finishing his degree at Minnesota State University, Mankato, Minnesota.


Photo of Gloria Velazquez

Gloria Velazquez was an IBM Software Engineer Intern during the summer of 2006. She is currently finishing her degree at University of Texas at El Paso, Texas.


Photo of Kathryn Lamont

Kathryn Lamont is a software engineer with IBM Software Group. She works on the installation team for the middleware product IBM WebSphere Process Server for Multiplatforms. Previously, Kathryn worked on IBM WebSphere Business Integration Server Express for iSeries. She was a technical mentor for the PHP on System i 2006 summer intern project. She joined the IBM Rochester team in 2004. Kathryn graduated from Iowa State University with a computer engineering degree. You can reach Kathryn at kathrynl@us.ibm.com.


Photo of David Peraza

David Peraza is a software engineer with IBM Systems and Technology Group. He works with WebSphere MQ integration with the System i platform. He was a technical mentor for the PHP on System i 2006 summer intern project. You can reach David at dperaza@us.ibm.com.




Rate this page


Please take a moment to complete this form to help us better serve you.



YesNoDon't know
 


 


12345
Not
useful
Extremely
useful
 


Back to top


IBM, AIX, AS/400, DB2, i5/OS, iSeries, OS/2, OS/390, OS/400, System i are trademarks of IBM Corporation in the United States, other countries, or both. Java and all Java-based trademarks are trademarks of Sun Microsystems, Inc. in the United States, other countries, or both. Microsoft, Windows, Windows NT, and the Windows logo are trademarks of Microsoft Corporation in the United States, other countries, or both. Linux is a registered trademark of Linus Torvalds in the United States, other countries, or both. Other company, product, or service names may be trademarks or service marks of others. Other company, product, or service names may be trademarks or service marks of others.