®
Welcome to:
PHP for System i Programmers
Erwin Earley (erwin.earley@us.ibm.com) Open Community Technologies System i Technology Center
IBM System i
1
IBM System i
Agenda
• What is PHP? • How does PHP work? • Zend Core for i5/OS • Basic syntax • Examples using the i5
Toolkit APIs
Connection Command call Record-level acess Program call Data areas System values
• Coding tips • Future directions • References
2
1
IBM System i
Web Development Stacks
L i n u x A p a c h e M P y H S P Q L W I M P i I y H n S S P d Q o L w s i 5 / O S A D P p B H a 2 P c h e i 5 / O S A p a c h e M P y H S P Q L
3
IBM System i
What is PHP ?
• PHP Hyerptext Processor
- Open source scripting language, mainly used for Web aplications
Can also be used as an administration language – like CL
- Code is usually embedded into HTML Web pages - Syntax is similar to C and Perl - Two “types” of PHP products:
Open source product Commercial
Zend = Open source product + additions + support
» The first supported PHP environment on System i5 (V5R4 and V5R3) » Zend Core for i5/OS was released at the end of July 2006
4
2
IBM System i
Why use PHP?
• Easy to learn • Most popular server side language on the Web • Thousands of free PHP applications are available • Fairly lightweight runtime environment
- Easy to administer (Zend provides tools)
• Provides many extensions for particular programming tasks
Database APIs (DB2, MySQL, Oracle, SQLServer, etc.) i5 PHP Toolkit (only available with Zend Core or Zend Platform) XML PDF Cryptography Web services
5
IBM System i
A Brief History of PHP
IBM, Oracle PHP 5.0 Endorse •XML, PHP SOAP, Yahoo! OOP 23M Standardizes Zend Studio on PHP PHP 4 Released 1M Internet Zeev Suraski, domains Zend Engine Rasmus Andi Gutmans Zend Founded develop Lerdorf develops PHP 3 PHP/FI
15M
10M
PHP Internet Domains
5M
1995
1997
1999
2000
2002
2004
Today
6
3
IBM System i
Why Do Developers Use PHP?
Zend's June 2003 market snapshot of the PHP community. The survey had over 10,000 respondents. http://www.zend.com/zend/php_survey_results.php
7
IBM System i
What Types of Applications are Developed in PHP?
Zend's June 2003 market snapshot of the PHP community. The survey had over 10,000 respondents. http://www.zend.com/zend/php_survey_results.php
8
4
IBM System i
What are System i Customer’s Doing with PHP?
1. Consolidation: Move PHP applications that are running on Windows or Linux that access data in DB2 to run in i5/OS to speed up or reduce complexity of the applications. 2. Modernization: Use PHP to web-enable green screen applications. 3. New application development: Create new applications with PHP on i5/OS including applications for the intranet, reporting, websites, and extranets. 4. Leveraging PHP portfolio: Run commercial or opensource PHP applications on i5/OS.
9
IBM System i
Zend Technologies
• The founders of Zend have been key contributors to the PHP
language since 1997
• Zend delivers commercial products that enable developers and IT
personnel to deliver and operate business-critical PHP applications
- Zend has been the leading supplier of PHP products and solutions for the last six years. Its products and solutions are being used by more than 15,000 companies worldwide. The Zend Engine (the PHP kernel) is being utilized on more than 22 million websites today - Zend takes the open source PHP code through rigorous testing for additional quality assurance and adds over 35 popular PHP extensions to deliver their PHP runtime environment
• Zend provides enterprise level support for the PHP environment
10
5
IBM System i
Zend Products for i5/OS
•
Zend Core for i5/OS
No Charge
- PHP runtime environment in i5/OS providing connections to DB2 UDB for i5/OS and RPG and COBOL applications
With 3 years Standard support
- Gold and Platinum support levels available for a fee
•
Zend Studio Professional for i5/OS
No Charge
- Integrated Development Environment on Windows or Linux
With 3 years Standard support
- Gold and Platinum support levels available for a fee
* Zend retail price for Core and Studio Professional on Intel for 5 developers with 3 years standard support – zend/com 7-6-06
= $5000 Value*
11
IBM System i
How does PHP work?
1. Browser requests a Web page (HTML) from the Web server. 2. The user enters data or performs an action. 3. The browser sends a request for a PHP file to the Web server. 4. The Web server forwards the PHP file to the PHP engine 5. The PHP engine processes the PHP code, optionally accessing server 6. 7. 8. 9.
resources (such as a database) or performing calculations. The PHP engine replaces the PHP code with the results of its processing The result (all HTML code) is sent to the Web server. The Web server sends the result as a response to the browser The browser loads the response code.
12
6
IBM System i
PHP Example
Original HTML
Test Page
HTML Processed by PHP Engine
Test page>
PHP Code
This is my php test page
13
IBM System i
How does Zend Core for i5/OS Work?
14
7
IBM System i
Setting up Zend for i5/OS
• Download Zend Core for i5/OS from zend.com
- RSTLICPGM installation - Creates the ZENDCORE library, /usr/local/Zend directory, and Zend-specific user profiles
• Start the Zend subsystem and the HTTP servers
- GO ZENDCORE/ZCMENU - Option 5 (Service Management menu) - Option 1 (Start Zend Core subsystem) and Option 4 (Start Apache server instances)
• Download Zend Studio for i5/OS from zend.com
- Integrated development environment - Runs on Windows, Linux, or MAC
15
IBM System i
Zend Core defalts
• Ports
- 89 – IBM HTTP Server for i5/OS port
Use this port number in the URL for your PHP applications •
Document root
- Put your files in the /www/zendcore/htdocs directory
•
Administration tools
- Setup tool
GO ZENDCORE/ZCMENU
- 8000 – i5/OS PASE Apache HTTP Server port
Configured to only accept requests from the local system
- Browser-based console
http://:89/ZendCore
- 6077 – i5 PHP Toolkit service port
- IBM Web Administration for i5/OS
http://:2001/HTTPAdmin
16
8
IBM System i
How does Zend Core for i5/OS Work?
Port 8000 Port 6077 Port 89
I5_COMD
http://:2001/HTTPAdmin
http://:89/ZendCore
17
IBM System i
Development Tools
18
9
IBM System i
• Zend Studio • Zend Frameworks • Zend Studio for Eclipse
19
IBM System i
Professional Integrated Development Environment
• Example: Zend Studio Professional • Complete out of the box experience • Includes installation and technical support • Typically provides many features and tools • Supports smart team development • Supports 3rd party integration (database, ftp, CVS,
SVN)
Well suited for team development of professional web applications
20
10
IBM System i
Zend Studio Features
• Can work with projects as well as stand-alone files • Syntax Highlighting for a number of file types • • • •
including PHP, XML, HTML Highlighting for matching brackets, quotes, and HTML tags PHP code completion HTML code completion Code Templates
Check out http://www.zend.com/products/zend_studio/feature_list#General for a full feature list
21
IBM System i
Zend Studio Features
• Debugger • Code Analyzer
- Highlight and show syntax errors while typing - Check for missing include files in an entire project
• SQL Support
- Allows connection to SQL servers - Visual display of databases, schemas, tables, fields, stored procedures and indexes in an SQL explorer tree - Table data viewing and editing
• Integration with other products/3rd Party solutions including:
Zend Platform Zend Framework Concurrent Versions System (CVS) Subversion (SVN) FTP
Check out http://www.zend.com/products/zend_studio/feature_list#General for a full feature list
22
11
IBM System i
What is PDT
• The PHP Development Tools Framework (PDT) is
an open-source, platform-independent software framework for the Eclipse platform • Features include
- An editor that provides syntax highlighting, code assistants, and code folding - Inspection functions for file and project outline as well as a PHP explorer view - Debug support for PHP scripts and web pages and well as management of web servers
Information on PDT is available at www.zend.com/pdt and www.eclipse.org/pdt
23
IBM System i
What is Zend Studio for Eclipse Zend Studio “Neon”
• Based on PDT as well as the features and
technology provided in Zend Studio • Provides an out of the box solution for PHP development • Features include
Code Generation Zend Framework Integration Profiling Code Coverage Advanced Debugging WYSIWYG editor for HTML FTP, Source, Control, Database Support
24
12
IBM System i
Zend Frameworks
• Zend Frameworks is a collection of pre-canned objects to facilitate the
building of modern applications and web services
• Examples of components included in the framework: - Zend_Acl: provides access control list (ACL) functionality and privileges management - Zend_Config: simplifies the use of configuration data for web applications - Zend_Controller and Zend_View: provides the infrastructure for Model-ViewController (MVC) websites. - Zend_Feed: provides a simple way to work with life syndicated feeds - Zend_Filter and Zend_Validate: facilitates the development of secure websites by providing basic tools necessary for filtering and validation. - Zend_Gdata: Google Data APIs that provide read/write access to services hosted at google.com such as Spreadsheets, Calendar, Blogger, and CodeSearch - Zend_Mail and Zend_Mimi: creates email messages and sends them - Zend_PDF: Create or read PDF documents from PHP applications. Can also modify existing PDF documents.
25
IBM System i
Zend Studio for Eclipse
• Zend Studio for Eclipse is currently available as a
beta and is code named “Neon”
- NOTE: The beta is actually a stand-alone product to show the capabilities and look-and-feel that will be in the Eclipse based product when it is released.
26
13
IBM System i
Zend Studio for Eclipse
• Neon is based on Zend Studio technology and the
Eclipse PHP development (PDT) project. • Why Eclipse?
- Worlds most popular open source development platform - Includes an extensible framework of tools and runtimes for building, deploying, and managing software across the development lifecycle - Standardization: support for multiple languages – simplifies creating an environment for blended language applications - Extensibility: Over 800 plug-ins available – additional functionality can be added quickly - Vibrant Open Source Community: Faster development of new technologies.
27
IBM System i
Basic syntax
28
14
IBM System i
Basics
• Specify a block of PHP code in an HTML file:
• Lines are delimited by a semicolon (;) • Displaying something:
print “Hello!”; echo ‘Error’; print • NOTE: The and tags around the content allows the new line
and tab characters to be displayed/presented correctly.
33
IBM System i
Arrays
• Arrays are the main data structure in PHP they are used to store related sets of
data rather then using multiple variables.
• Associative arrays: - Mapping of a key to a value (name-value pairs) - Typically used for storing information where the key describes the data
$myarray = array("first" => 1, "second" => 2, "third" => 3); $num = $myarray['first'];
• Numeric (or Enumerated) arrays: - Mapping of an index to a value - Typically used for storing pieces of related information, such as lists. - The following method creates an empty array and then pushes values onto the end of the list
$myarray = $myarray[] $myarray[] $myarray[] array(); = "Monday"; = "Tuesday"; = "Wednesday";
- The following method creates the array in a single step (and is technically faster then the first method)
$myarray = array("Monday", "Tuesday", "Wednesday"); $num = $myarray[1];
34
17
IBM System i
Arrays
• An array in PHP is actually an ordered map - Keys are mapped to values • Can be used as a list, vector, hashtable,
dictionary, collection, stack, queue, etc. • Can be of three types:
- Numeric
$customer[0] = ‘Foo Widgets’;
- Associative
$customer[‘name’] = ‘Foo Widgets’;
- Multidimensional
$data[‘customer’][‘name’] = ‘Foo Widgets’;
35
IBM System i
Outputting contents of an array (typically for debug)
• PHP provides a function (print_r) that will output the contents of an array • Typically it used for debug purposes • The array will be output as plan text – not HTML – would need to be
encapsulated in HTML tags if you want it output within an HTML page PHP Code
"Erwin", "location"=>"Rochester"); print_r($people); ?> )
Debugger Output
Array ( [name] => Erwin [location] => Rochester
36
18
IBM System i
Accessing values within an array
• The foreach() loop can be used to iterate through
the values in an array
PHP Code
Output
This color is blue This color is green This color is orange
37
IBM System i
Accessing values in an Associative Array
• The following syntax allows you to loop through both
the keys and values of an associative array
PHP Code
2, “second” => 4, “third” => 8, “fourth” => 16); foreach($powersof2 as $exponent => $result) { echo "2 raised to the $exponent power equals $result\n"; } ?>
Output 2 2 2 2 raised raised raised raised to to to to the the the the first power equals 2 second power equals 4 third power equals 8 fourth power equals 16
38
19
IBM System i
Internal Array Pointer
• Arrays have an internal pointer that is used to indicate the
current element of the array
• The each() function returns the current key and value pair. • The list() function can be used to take a array of values and
assign them to different variables
• The array pointer is not moved back to the begging of the
array until you call reset() passing the variable containing the array to be reset
39
IBM System i
Internal Array Pointer
PHP Code
Output I I I I I like like like like also eating Steak eating Chicken eating Potatoes eating Pork like eating Corn
40
20
IBM System i
Loops
• Array processing is important in PHP
- Need to know various ways to loop through arrays
• foreach
foreach ($myarray as $key => $value) {
print “$key is $value”;
}
• for
$size = count($myarray); for ($i = 1; $i $i) {$myarray[$i]}”;
} - Use brackets for array variables in double quotes
41
IBM System i
Loops
• While
$i = 0; while ($i {$myarray[$i]}”; i++;
}
• Do-while (ensures the loop is performed at least once)
$i = 0; do {
print “ {myarray[$i]}”; $i++;
} while ($i 0) $i + 10; { $i + 100;
}
•
if-else
if ($i
47
IBM System i
Basic PHP Syntax – Arrays: Example
• Create an array to store a list of favorite tv shows • Loop through the array adding the phrase "I like
watching" to the start of each element using the internal array pointer
• Loop through the array a second time using a
foreach loop to print out each element in the array
48
24
IBM System i
Basic PHP Syntax – Arrays: Example One Possible Solution
I like watching Lost I like watching 24 I like watching Deal or No Deal
49
IBM System i
Functions
• Functions can be used to accomplish any number of separate tasks • Generally functions work by being passed a series of parameters and
returning a result:
- echo "strtoupper(“PHP for System i Programmers");
//PHP FOR SYSTEM I PROGRAMMERS
• A function can be put almost anywhere that a variable or string would
normally appear in the PHP code
• PHP will execute the function and replace it with the return value. • A function can change the value of a variable by assignment of the return
value to the variable:
- $session = “PHP for System i Programmers"; - $session = strtoupper($session); - echo $session; // PHP FOR SYSTEM I PROGRAMMERS
50
25
IBM System i
String Functions – A couple of examples
• strpos() will search a string for an occurrence of another string. - The value returned will be the position (index) in the first string where the second string occurs.
$string = “PHP for System i Programmers"; echo $position = strpos($string, “System"); // 8
• substr() will return a portion of a string depending on the input
parameters
- echo substr($string, $position); - echo substr($string, $position, 6); - echo substr($string, -11); // System i Programmers // System // Programmers
51
IBM System i
Customized Functions
• In addition to the built-in functions provided by PHP, we can
develop our own customized functions within our PHP code
• Functions help to make larger applications easier to
develop/maintain since different tasks can be allocated to different functions
• Here is an example of how to code up a customized function:
function x5($number) {
return ($number * 5);
} echo x5(10);
// 50
52
26
IBM System i
Function Scope
• Variables are scoped to the function in which they are defined. • This is probably best explained with an example: function scopedemo($fruit) {
$fruit = 20; echo $fruit; // 20
} $fruit = 10; scopedemo(fruit); echo $fruit;
// 10
• The thing to make note of is that the variable $fruit is independent within
each function.
53
IBM System i
GLOBAL VARIABLES
";
Tuesday before running the function Saturday inside the function
}
It is Saturday after running the function
// print the variable print "It is $today before running the function"; // call the function getDay(); // print the variable print "It is $today after running the function"; ?>
54
27
IBM System i
Passing variables by reference
• "; } It is Tuesday inside the function // call function setDay($today); It is Tuesday outside the function
// print the value of the variable print "It is $today outside the function"; ?>
55
IBM System i
Optional Parameters
• Functions can accept optional as well as required parameters • The optional parameters have to be defined after the required parameters • A parameter is made optional by assigning a default value to the parameter in the
function definition:
function optionalDemo($greeting, $count = 1) {
for ($i = 0; $i make = $make; $this->model = $model; } function printMake() { echo $this->make . "\n"; } } $mustang = new car("Ford", "Mustang"); $mustang->printMake(); $camaro = new car("Chevrolet", "Camaro"); $camaro->printMake(); /* Ford Chevrolet */
59
IBM System i
Object Example – NOTES
• The code on the preceding slide creates a class called car • The class has two properties – make and model • It also has two methods __construct() and printMake() • The line $mustang = new car(…); a new instance of car is
created and stored inside the variable $mustang.
• The methods of the object are accessed through the variable
that stores it.
• The method named __constrct() is automatically called when
the object is instantiated.
60
30
IBM System i
i5 PHP Toolkit examples
61
IBM System i
Disclaimer
• You can use these examples
- To get started with PHP on i5 - To learn what PHP on i5 can do
• The code is not supported by IBM or Zend • Do not use them in a production environment without first:
- Adding more robust error handling and input validation - Securing your i5/OS and PHP environment
Authentication Authorization Object-level security
62
31
IBM System i
i5 Toolkit APIs
• Are shipped with Zend products
- Zend core for i5/OS - Zend Platform for i5/OS
• Geared towards accessing i5 data and resources from PHP
- Similar in purpose to the IBM Tookbox for Java
• Note: the I5_COMD job must be running in the ZEND
subsystem - Use the Zend menu to start:
GO ZENDCORE/ZCMENU Option 5 (Service Management menu) Option 8 (Start I5_COMD service)
63
IBM System i
PHP Toolkit for i5/OS – list of functions
• Connection management • Data retrieval • Native file access
- i5_connect - i5_close - i5_adopt_authority - i5_error - i5_errno - i5_errormsg
• Command calls
- i5_command
• Program calls
- i5_program_prepare - i5_program_prepare_PC ML - i5_program_call - i5_program_close
- i5_fetch_array - i5_fetch_assoc - i5_fetch_objec t - i5_fetch_row - i5_info - i5_field_len - i5_field_name - i5_field_scale - i5_field_type - i5_list_fields - i5_num_fields - i5_result
-
i5_open i5_addnew I5_edit I5_delete i5_cancel_edit i5_setvalue i5_update i5_range_from i5_range_to i5_range_clear i5_data_seek i5_seek i5_bookmark i5_free_file i5_new_record i5_update_record i5_get_keys
64
32
IBM System i
PHP Toolkit functions
• System values • Job logs • User space
- i5_get_system_value
• Data areas
- i5_jobLog_list - i5_jobLog_list_read - i5_jobLog_list_close
• Active jobs
- i5_data_area_prepare - i5_data_area_receive - i5_data_area_send - i5_data_area_close • Print/Get spooled file - i5_spool_list - i5_spool_list_read - i5_spool_list_close - i5_spool_get_data - i5_spool_from_file
- i5_userspace_crearte - i5_userspace_prepare - i5_userspace_get - i5_userspace_put
• Data Queue
- i5_job_list - i5_job_list_read - i5_job_list_close
• Objects list
- i5_dtaq_prepare - i5_dtaq_recieve - i5_dtaq_send - i5_dtaq-close
- i5_object_list - i5_object_list_read - i5_object_list_close
65
IBM System i
Connection
• Must connect to the i5 system to use any of the other APIs
- Connecting
i5_connect
Need system, user profile name, and password as parameters The system can only be localhost or 127.0.0.1
i5_close
Always close a connection you’ve opened
i5_adopt_authority
Can adopt other authorities while running
- Error handling
i5_error
Get data about an error
i5_errno
Error number
i5_errormsg
Error message
66
33
IBM System i
Connection: HTML code
User profile: Password:
67
IBM System i
Connection: PHP code
Error number" . i5_errorno() . "msg = " . i5_errormsg()); } print “Connection successful"; // Close the connection i5_close($conn); ?>
68
34
IBM System i
Command call
• Call a CL command on the system
- i5_command
Takes up to four parameters:
Command (Optional) Array of input values (Optional) Array of output values (Optional) Connection to use
- i5_cmdget
Can be used to retrieve output from running a command
• Check the CL reference manual for commands and
parameters
- http://publib.boulder.ibm.com/infocenter/iseries/v5r4/topic/rbam6/rbam6clma in.htm
69
IBM System i
Command call: HTML code
Send a message (SNDMSG) Message: Receive a message (RCVMSG)
70
35
IBM System i
Command call: PHP code
Connection failed! " . i5_errno() . "msg = " . i5_errormsg()); // Send the message if ($_POST['task'] == 'send') { // Get the message $message = $_POST['message']; // Call the command $cmd1 = i5_command("SNDMSG MSG('$message') TOUSR(PHPUSER)"); if (!$cmd1) die("Command failed. " . i5_errno() . " msg = " . i5_errormsg()); print "Message sent.";
71
IBM System i
Command call: PHP code (continued)
// If a message is being received } else if ($_POST['task'] == 'get') { // Call the command, passing in an array for input (empty) and output (MSG) $cmd2 = i5_command("RCVMSG MSGQ(QUSRSYS/PHPUSER) MSGTYPE(*NEXT) MSGKEY(*TOP)", array(), array("MSG" => "msgtext", "MSGDTA" =>"msgdata", "MSGID" => "msg_id")); if (!$cmd2) die("Command failed. Error number = " . i5_errno() . " msg = " . i5_errormsg()); // Display the message text print "Message: $msgtext"; //print "Message: $msgtext" . " Message Data: $msgdata" . "message id: $msg_id"; // Close the connection } // Close the connection i5_close($conn); ?>
72
36
IBM System i
Command Call Example Form and Output
73
IBM System i
Record-level access
• i5_open - Pass in library/file and type of "open" mode
i5_open_read, i5_open_readwrite, i5_open_commit, i5_openshrrd, i5_open_shrupd
Etc
• i5_list_fields - Get an array of the names of the fields in the file • i5_fetch_row - Get an array of the fields in a record, passing in which record to fetch
i5_read_seek (current) i5_read_next (default) i5_read_prev i5_read_first i5_read_last
74
37
IBM System i
Record-level access: HTML code
Library (schema): File (table):
75
IBM System i
Record-level access: PHP code
// Get input data $dbfile = $_POST['tbl']; $dblib = $_POST['lib']; // Open the file $file = i5_open("$dblib/$dbfile", I5_OPEN_READ); if (!$file) die("Error while attempting to open file mode=READ"); // Print a table row of field names $fields = i5_list_fields($file); // returns an array print ""; // Parse the array foreach ($fields as $value) { print "$value"; } print "\n";
76
38
IBM System i
Record-level access: PHP code
// Print records $rec = i5_fetch_row($file, I5_READ_FIRST); // get array while ($rec) // while there is a record... { // Print each field in the array foreach ($rec as $value) { print “$value"; } print "\n"; // Get next record $rec = i5_fetch_row($file, I5_READ_NEXT); } // loop print ""; // finish off the table
77
IBM System i
Record-level access: PHP code Example Form and Output
78
39
IBM System i
Program call
• i5_program_prepare
- "Opens" the program to be run - Includes a description of input and output parameters
• i5_program_call
- Pass in the prepared program, an array of values for input parameters, and an array of placeholders for output parameters
• i5_program_close
- Closes the program
79
IBM System i
Program call: HTML code
String: Number:
80
40
IBM System i
Program call: CL code
PGM DCL DCL CHGVAR CHGVAR ENDPGM PARM(&SOMESTRING &SOMENUM) VAR(&SOMESTRING) TYPE(*CHAR) LEN(10) VAR(&SOMENUM) TYPE(*DEC) LEN(15 5) VAR(&SOMESTRING) VALUE(%SST(&SOMESTRING 1 3)) VAR(&SOMENUM) VALUE(&SOMENUM + 1)
81
IBM System i
Program call: PHP code
// Describe the program parameters $description = array( array("name" => "SOMESTRING", "IO" => I5_INOUT, "Type" => I5_TYPE_CHAR, "Length" => "10"), array("name" => "SOMENUM", "IO" => I5_INOUT, "Type" => I5_TYPE_PACKED, "Length" => "15.5") }; $pgm = i5_program_prepare("EEARLEY/MYPGMCALL", $description); if (!$pgm) die("Program prepare error. Error number = " . i5_errno() . " msg = " . i5_errormsg());
82
41
IBM System i
Program call: PHP code
$parmIn = array("SOMESTRING" => $_POST["str]", "SOMENUM => $_POST["nbr]"); // input parameters $parmOut = array("SOMESTRING" => "SOMESTRING", "SOMENUM" => "SOMENUM"); // output parameters $ret = i5_program_call($pgm, $parmIn, $parmOut); if (!$ret) die("Program call errno=". i5_errno(). " msg = " . i5_errormsg()); // Display the output from the program print “The first three characters of the string: $SOMESTRING"; print "The number, incremented: $SOMENUM"; // Close program call i5_program_close($pgm);
83
IBM System i
$description
Array ( [0] => Array ( [name] => SOMESTRING [IO] => I5_INOUT [Type] => I5_TYPE_CHAR [Length] => 10 ) [1] => Array ( [name] => SOMENUM [IO] => I5_INOUT [Type] => i5_TYPE_PACKED [Length] => 15.5 ) ) ) )
$parmIn
Array ( [SOMESTRING] => [SOMENUM] =>
$parmOut
Array ( [SOMESTRING] => SOMESTRING [SOMENUM] => SOMENUM
$pgm= $i5_program_prepare(“EEARLEY/MYPGMCALL”, $description)
$i5_program_call($pgm, $parmIn, $parmOut)
84
42
IBM System i
Data areas
• i5_data_area_create • i5_data_area_read
- Name of the data area - Its size (in bytes) - Name - (Optional) An offset (where to start) - (Optional) The length of data to read
• i5_data_area_write
- Name - Value to write - An offset (where in the value to start) - Length of the value to write
• i5_data_area_delete
- Name
85
IBM System i
Data areas: HTML code
First name: Last name: Starting position of substring: Length of substring:
86
43
IBM System i
Data areas: PHP code
// Get input data $inputstring = "'" . $_POST["first"] . " " . $_POST["last"] . "'"; $start = intval($_POST["start"]); $length = intval($_POST["length"]); // Create data area if (i5_data_area_create("EEARLEY/DATAAREA", 256)) { // Write to data area if (i5_data_area_write("EEARLEY/DATAAREA", $inputString, 1, 50)) { // Read from data area $outputString = i5_data_area_read("EEARLEY/DATAAREA", $start, $length); print "Data read from data area: " . $outputString; } else { print "i5_data_area_write error: " . var_dump(i5_error()); } } else { print “i5_data_area_create error: " . var_dump(i5_error()); } // Delete data area i5_data_area_delete("EEARLEY/DATAAREA");
87
IBM System i
System values
// Retrieve the system date and time values print "The date is: " . i5_get_system_value("QMONTH") . "/" . i5_get_system_value("QDAY") . "/" . i5_get_system_value("QYEAR"); print "The time is: " . i5_get_system_value("QHOUR") . ":" . i5_get_system_value("QMINUTE") . ":" . i5_get_system_value("QSECOND");
88
44
IBM System i
Accessing DB2/400
• Server/connection
db2_bind_param db2_client_info db2_close db2_connect db2_cursor_type db2_exec db2_execute db2_prepare - db2_pconnect - db2_server_info - db2_statistics • Result
• Fetch
• Errors
- db2_free_result - db2_next_result - db2_result
• Commit/Rollback
- db2_autocommit - db2_commit - db2_rollback
- db2_fetch_array - db2_fetch_assoc - db2_fetch_both - db2_fetch_object - db2_fetch_row • Field information - db2_field_display_size - db2_field_name - db2_field_num - db2_field_precision - db2_field_scale - db2_field_type - db2_field_width • Key information - db2_foreign_keys - db2_primary_keys • Statement - db2_free_stmt
-
db2_conn_error db2_conn_errormsg db2_stmt_error db2_stmt_errormsg db2_column_privileges db2_columns db2_procedure_columns db2_procedures db2_special_columns db2_num_fields db2_num_rows db2_table_privileges db2_tables
• Column/Procedure
• Table information
All of these APIs are documented online at php.net - Preferred db2_ SQL statement execution APIs (performance) • - Non-preferred db2_ SQL statement execution API
89
IBM System i
Server connection – db2_connect API
• There are few connections options in PHP
- db2_connect(“”,””,””) – local server
The database connection job is create under the same user as the Apache httpd server profile NOBODY (*USER).
- db2_connect(“*LOCAL", “SAM", “PASSWROD")– local server
The database connection job is created under the user profile SAM/PASSWROD.
- db2_connect(“10.1.1.33", “SAM", “PASSWROD") – remote remote database connection job is created under the user server
The profile SAM/PASSWROD.
Tip: Use WRKRDBDIRE to get the database name on the remote
90
45
IBM System i
I5 ToolKit vs. DB2 Extensions
• The i5 Toolkit represents functions for accessing
native i5/OS resources
- The toolkit is specific to the Zend products for i5/OS - The toolkit functions can only access local resources (i.e., resources on the same i5/OS partition as Zend Core) unless you setup remote connections (such as DDM) outside of the Zend Core environment. - All i5 Toolkit functions begin with the characters “i5_”
• The DB2 functions represent an extension to the
PHP language
- The DB2 extensions are starting to become part of the mainstream php language offering and will be available on platforms other the i5/OS - The DB2 extensions can access both local and remote DB2 resources through extablished network connections - All DB2 functions begin with the characters “db2_”
91
IBM System i
i5 Toolkit vs. DB2 Extensions
i5_*
I5_COMD
Zend Core PASE i5/OS
I5/OS
Resource
db2_*
TCP/IP
db2_*
I5/OS
Resource
i5/OS
92
46
IBM System i
Coding tips
• Use the Zend Studio browser toolbar to debug pages
- Integrated with Zend Studio and the Zend Core debugger
• To see the type and values of variables
- var_dump($_POST['msg']);
• Only deviate a little at a time from an example
- Easier to pinpoint what you did to break it
• Check out the forums at http://www.zend.com/forums/
- Zend Core for i5/OS - Zend Platform for i5/OS - Zend Studio for i5/OS
93
IBM System i
Resources: Books
• Sklar, David. Learning PHP 5. O'Reilly Media, Inc. 2004 • Zend Technologies. Zend Core for i5/OS: User Guide
- PDF included with Zend Core for i5/OS - Contains the i5 Toolkit documentation
• Zend Technologies. Zend Studio 5.2 for i5/OS: User
Guide - PDF included with Zend Studio for i5/OS
• PHP on i5 Redbook
- SG24-7327-00
94
47
IBM System i
Resources: Web sites
• PHP documentation at
php.net
- Official open-source PHP documentation - http://www.php/net/docs.php
• Zend Developer Zone
- Articles tutorials, samples, etc. - http://devzone.zend.com/public/vie w
• i5php.net
- Articles, downloads, forums, etc - http://i5php.net
95
IBM System i
Zend in the News – Recent Announcements
• Zend Core 2.5 Features - MySQL (Community Edition) will be delivered and installed - Extensions to the language will be added to provide the ability to connect PHP applications running in i5/OS to a SQL server database running under Windows
In version 2.5 this is a preview – will be a supported feature in a future release
• Zend Studio for Eclipse – Beta - Can only be used as a stand-alone tool at the moment - Will function as an Eclipse plug-in when the product becomes generally available during Q1 2008.
96
48
IBM System i
IBM and MySQL Announce Plans for i5/OS and DB2
• MySQL is the leading open source database
with over 11 million installations • MySQL is the most popular database to use with PHP applications
• Step 1: MySQL database to be supported on
i5/OS
- Enables customers to deploy MySQL-based applications on i5/OS • Step 2: Plan to integrate MySQL with DB2 on
i5/OS
- Enables MySQL-based applications to store data in DB2 on i5/OS
System i customers get the benefit of being able to use thousands of new open source applications while continuing to have one easy to use data store with DB2.
97
IBM System i
IBM and MySQL announce plans for i5/OS and DB2
• MySQL is the leading open-source database, with 10M+ installations • MySQL is the most popular database to use with PHP applications • Joins the expanding communities of PHP, MySQL and System i Existing DB2 apps New MySQL apps
DB2 server
MySQL server
DB2 storage engine
Joins
Specialty storage engines
"MySQL's and IBM's plan for the MySQL database management system to run on the System i platform brings hundreds of new applications to System i and should be welcome news to small and midsize businesses." - Gartner
98
49
IBM System i
Other Useful Presentations
• Introduction to PHP: Provides a general overview of PHP • •
•
•
including usage, history, and basic syntax PHP for System i Perspectives: Provides an overview of PHP on System i PHP and MySQL in i5/OS – New Stacks and New Solutions: Discusses how PHP and MySQL can be used together to deploy open community solutions in i5/OS PHP Development Tools: Discusses some of the available PHP development tools including Zend Studio, Zend Frameworks, Zend Studio for Eclipse, and PHP Development Tools Frameworks (PDT) Net.Data and PHP – A Comparison Study: Compares features of Net.Data and PHP
99
IBM System i
Questions
100
50
IBM System i
Trademarks
Trademarks The following are trademarks of the International Business Machines Corporation in the United States and/or other countries. For a complete list of IBM Trademarks, see www.ibm.com/legal/copytrade.shtml: AS/400, DBE, e-business logo, ESCO, eServer, FICON, IBM, IBM Logo, iSeries, MVS, OS/390, pSeries, RS/6000, S/30, VM/ESA, VSE/ESA, Websphere, xSeries, z/OS, zSeries, z/VM The following are trademarks or registered trademarks of other companies Lotus, Notes, and Domino are trademarks or registered trademarks of Lotus Development Corporation Java and all Java-related trademarks and logos are trademarks of Sun Microsystems, Inc., in the United States and other countries LINUX is a registered trademark of Linux Torvalds UNIX is a registered trademark of The Open Group in the United States and other countries. Microsoft, Windows and Windows NT are registered trademarks of Microsoft Corporation. SET and Secure Electronic Transaction are trademarks owned by SET Secure Electronic Transaction LLC. Intel is a registered trademark of Intel Corporation * All other products may be trademarks or registered trademarks of their respective companies. NOTES: Performance is in Internal Throughput Rate (ITR) ratio based on measurements and projections using standard IBM benchmarks in a controlled environment. The actual throughput that any user will experience will vary depending upon considerations such as the amount of multiprogramming in the user's job stream, the I/O configuration, the storage configuration, and the workload processed. Therefore, no assurance can be given that an individual user will achieve throughput improvements equivalent to the performance ratios stated here. IBM hardware products are manufactured from new parts, or new and serviceable used parts. Regardless, our warranty terms apply. All customer examples cited or described in this presentation are presented as illustrations of the manner in which some customers have used IBM products and the results they may have achieved. Actual environmental costs and performance characteristics will vary depending on individual customer configurations and conditions. This publication was produced in the United States. IBM may not offer the products, services or features discussed in this document in other countries, and the information may be subject to change without notice. Consult your local IBM business contact for information on the product or services available in your area. All statements regarding IBM's future direction and intent are subject to change or withdrawal without notice, and represent goals and objectives only. Information about non-IBM products is obtained from the manufacturers of those products or their published announcements. IBM has not tested those products and cannot confirm the performance, compatibility, or any other claims related to non-IBM products. Questions on the capabilities of non-IBM products should be addressed to the suppliers of those products. Prices subject to change without notice. Contact your IBM representative or Business Partner for the most current pricing in your geography. References in this document to IBM products or services do not imply that IBM intends to make them available in every country. Any proposed use of claims in this presentation outside of the United States must be reviewed by local IBM country counsel prior to such use. The information could include technical inaccuracies or typographical errors. Changes are periodically made to the information herein; these changes will be incorporated in new editions of the publication. IBM may make improvements and/or changes in the product(s) and/or the program(s) described in this publication at any time without notice. Any references in this information to non-IBM Web sites are provided for convenience only and do not in any manner serve as an endorsement of those Web sites. The materials at those Web sites are not part of the materials for this IBM product and use of those Web sites is at your own risk.
101
51