why php on ibm i

21
Why PHP on IBM i Why PHP on IBM i Why, where and how you can and should use PHP on IBM i

Upload: leonard-acevedo

Post on 30-Dec-2015

37 views

Category:

Documents


0 download

DESCRIPTION

Why PHP on IBM i. Why, where and how you can and should use PHP on IBM i. Who is Jeff Olen and why should we listen to him?. IBM i developer for 20+ years Vice-President and Co-founder of Olen Business Consulting, Inc. Author of “IBM i Programmers Guide to PHP”. PHP on IBM i - History. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Why PHP on IBM i

Why PHP on IBM iWhy PHP on IBM i

Why, where and how you can and should use PHP on IBM i

Page 2: Why PHP on IBM i

Who is Jeff Olen and why Who is Jeff Olen and why should we listen to him?should we listen to him?

• IBM i developer for 20+ years

• Vice-President and Co-founder of Olen Business Consulting, Inc.

• Author of “IBM i Programmers Guide to PHP”

Page 3: Why PHP on IBM i

PHP on IBM i - HistoryPHP on IBM i - History

• As of V5R2 (approx. 2003), IBM i developers have had the ability to compile and run PHP and MySQL in the PASE environment.

• April 2006 – IBM selects Zend to bring PHP to the IBM i and announces that it will port PHP development tools (Core, Platform and Framework) to IBM i.

• February 2009 – New IBM i shipments come preloaded with Zend Core PHP.

Page 4: Why PHP on IBM i

Why PHP on IBM i?Why PHP on IBM i?

• Easy to make the transition from RPG to PHP.• Do not need to know object-oriented techniques.• Most popular web development language.• Huge open source community with vast amount

of sample code and documentation.• Affordability (Did we mention that Zend Core and

Zend Studio for i5/OS are free?)• Extensions for most common applications.• Many more…

Page 5: Why PHP on IBM i

Zend Core for i5/OSZend Core for i5/OS

Allows PHP applications to access:

• DB2 using RPG-like database access functions

• Native RPG, Cobol, C and CL program calls

• Native commands

• Spool files

• Data areas

• User spaces

• System values

• Data queues

• Message queues

• Job Logs

Page 6: Why PHP on IBM i

Value-Add for IBM i Value-Add for IBM i

• By running PHP applications on the IBM i you gain the security, stability and reliability that the IBM i is known for.

• Quickly and easily implement new applications.– Open Source applications– Existing sample code

• Leverage existing business logic. For example RPG & Cobol programs.

• Cost effective web solution (did we mention its free?)

• Does not add overhead like some other solutions.

Page 7: Why PHP on IBM i

Access IBM i DB2 tables with Access IBM i DB2 tables with PHPPHP• IBM DB2 functions

– Completely system independent

• Zend Toolkit Class library – Native File access i5_xxxx– Provides ready access to IBM i DB2 tables– Eases transition from RPG to PHP

• MySQL IBMDB2i storage engine– Allows for quickly porting open source applications to

DB2 database.– Provides an easy way to prototype IBM i PHP

applications without access to an IBM i.

Page 8: Why PHP on IBM i

How to start How to start

• Install Zend Core and/or Zend Platform on your IBM i (Check, it might already be there.)

• Start the Zend Core Subsystem and Apache Servers.

• Install Zend Studio (or another IDE) on a Windows client.

• Get on the internet and download some open source examples and/or simple applications.

• Save the sample code in the htdocs directory on your IBM i.

• Open a browser and enter the URL.• That’s it!

Page 9: Why PHP on IBM i

Questions?Questions?

Page 10: Why PHP on IBM i

IBM i DB2 sampleIBM i DB2 sample<?php// Set the database name. // This is an IBM i System table (it exists on all IBM i machines)$tableName = 'SYSTABLES';$libName = 'QSYS2';

// create the connection to the IBM i relational databaseif (!$dbh = db2_connect(“localhost",“jolen",“pass123")) {

echo "connection failed.<br>";echo db2_conn_errormsg() . "<br>";die();

}

// Retrieve a resultset of the column info for the specified tableif (!$cols = db2_columns( $dbh, null, $libName, $tableName, '%' )) {

echo "columns retrieval failed.<br>";echo db2_stmt_errormsg() . "<br>";die();

}

// output the Library and name of the table$column = db2_fetch_assoc($cols);echo "Table: ";echo $column["TABLE_SCHEM"]."/".$column["TABLE_NAME"]."<br>";

// output all the column namesdo {

echo $column["COLUMN_NAME"]."<br>";} while ($column = db2_fetch_assoc($cols));

db2_close($dbh);?>

Page 11: Why PHP on IBM i

IBM i DB2 sample outputIBM i DB2 sample output

Page 12: Why PHP on IBM i

IBM DB2 Function sampleIBM DB2 Function sampleSource name: displayColumns.php

<?phpfunction displayColumns( $libraryName, $tableName ) {

if (!isset($dbh)) {$dbh = db2_connect("localhost", "jolen", "pass123");if (!$dbh) {

echo "connection failed.<br>";echo db2_conn_errormsg() . "<br>";die();

}}// retrieve a result set with the column info for the// file specified at the top of the script.if (!$cols = db2_columns( $dbh, null, $libraryName, $tableName, '%' )) {

echo "columns retrieval failed.<br>";echo db2_stmt_errormsg() . "<br>";die();

}// Fetch the first row and output the file name and library name from the result set.$column = db2_fetch_assoc($cols);echo "Table: ";echo $column["TABLE_SCHEM"]."/".$column["TABLE_NAME"]."<br>";

// loop thru all the result set rows and list all the column names.do {

echo $column["COLUMN_NAME"]."<br>";} while ($column = db2_fetch_assoc($cols));

}

Page 13: Why PHP on IBM i

IBM DB2 Function sampleIBM DB2 Function sample<?phprequire_once(‘displayColumns.php');

displayColumns( 'QSYS2', 'SYSTABLES' );echo "<br><br>";displayColumns( 'QSYS2', 'SYSROUTINES' );

?>

Page 14: Why PHP on IBM i

IBM DB2 Class exampleIBM DB2 Class exampleSource name: fileinfo.class.php

<?php

class tableInfo {

var $columns;var $table;var $library;var $dbh;

function __construct( $libraryName, $tableName ) {

if (!isset($this->dbh)) {$this->dbh = db2_connect("localhost", "jolen", "pass123");if (!$this->dbh) {

echo "connection failed.<br>";echo db2_conn_errormsg() . "<br>";die();

}}

$this->library = $libraryName;$this->table = $tableName;

}

Page 15: Why PHP on IBM i

// retrieve a result set with the column info for the file specified at the top of the script.function retrieveColumnInfo() {

if (!$this->columns = db2_columns( $this->dbh, null, $this->library, $this->table, '%' )) {echo "columns retrieval failed.<br>";echo db2_stmt_errormsg() . "<br>";die();

}} // end of function

// retrieve a result set with the column info for the file specified at the top of the script.function displayColumnInfo () {

echo "Table: ";echo $this->library."/".$this->table."<br>";$firstpass = TRUE;

while ($column = db2_fetch_assoc($this->columns)) {if ($firstpass) {

$firstpass = FALSE;echo "<table border=1><tr>";foreach ($column as $key => $value) {

echo "<th>".$key."</th>";}echo "</tr>";

}

echo "<tr>";foreach ($column as $value) {

echo "<td>".$value."</td>";}

echo "</tr>";}echo "</table>";

} // end of function

} // end of class code

IBM DB2 Class example IBM DB2 Class example ContinuedContinued

Page 16: Why PHP on IBM i

<?php

require_once(‘fileinfo.class.php');

$sysTables = new tableInfo('QSYS2','SYSTABLES');

$sysRoutines = new tableInfo('QSYS2','SYSROUTINES');

$sysRoutines->retrieveColumnInfo();

$sysRoutines->displayColumnInfo();

$sysTables->retrieveColumnInfo();

$sysTables->displayColumnInfo();

?>

IBM DB2 Class exampleIBM DB2 Class example

Page 17: Why PHP on IBM i

Questions?Questions?

Page 18: Why PHP on IBM i

Important LinksImportant LinksIBMDB2i storage engine install and docs:http://solutions.mysql.com/engines/ibm_db2_storage_engine.html

IBM Redbook on IBMDB2i:http://www.redbooks.ibm.com/abstracts/sg247705.html?Open PHP Extensionshttp://pecl.php.net

IBMDB2 documentationhttp://www.php.net/ibm_db2

Subversion source controlhttp://subversion.tigris.org

Subclipse – subversion Eclipse Team Provider plug-in (works with RDi/WDSc)http://subclipse.tigris.org

Page 19: Why PHP on IBM i

OPC – Other People’s CodeOPC – Other People’s Code

Hotscripts.com – “The nets largest script collection portal”

phpClasses.org – PHP classes repository

SourceForge.net – Find and develop open-source software

Page 20: Why PHP on IBM i

Next stepsNext steps• Training

– Zend training classes– Olen Business Consulting, Inc. training (insert shameless sales pitch here)– Personalized training on-site

• Source control/Version control– Subversion can be installed on IBM i– Subclipse plug-in works with WDSc/RDi

• Database abstraction– DAO, VO and PDO– OO Classes

• Object-oriented coding– Not necessary to begin using PHP– You will rapidly see the advantages once you get comfortable with PHP

• Zend Framework and Zend Platform

• Certification

Page 21: Why PHP on IBM i

Questions?Questions?