Why PHP on IBM i


Published on

  • Be the first to comment

  • Be the first to like this

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide
  • PASE – Portable Application Solutions Environment Starting in February of this year all IBM i’s come pre-loaded with Zend Core
  • Significant websites are built on PHP include: Facebook , [36] Wikipedia ( MediaWiki ), [37] Yahoo! , [38] and YouTube , Over 20 million websites use PHP – per Netcraft research data company in England. You can find PHP extensions for FTP, PDF, security, XML and Web services such as JSON (JavaScript Object Notation) at pecl.php.net.
  • Zend Core for i5/OS is a PHP extension/Add-on developed by Zend and IBM. It provides IBM i specific functionality in PHP. Native Command example: RTVJOBA, SBMJOB, CRTPF, etc… Allows you to leverage your existing code Zend was good enough to provide sample code showing how to use these functions. Check out the demo_for_toolkit_classes.php and toolkit_classes.php.
  • Open source apps: SugarCRM, MediaWiki (wikipedia), and phpMyAdmin. Overhead example: WAS – Websphere application server
  • Other PHP IDEs: Zend Studio (free for IBM i), Komodo, Eclipse (the only free software other than Studio for i), and PHPEdit. Learn HTML. There’s no way to avoid this.
  • Reiterate uppercase field names
  • Require, require_once, include, and include_once mention warning vs error Ask if there are any questions.
  • Why PHP on IBM i

    1. 1. Why PHP on IBM i Why, where and how you can and should use PHP on IBM i
    2. 2. Who is Jeff Olen and why should we listen to him? <ul><li>IBM i developer for 20+ years </li></ul><ul><li>Vice-President and Co-founder of Olen Business Consulting, Inc. </li></ul><ul><li>Author of “IBM i Programmers Guide to PHP” </li></ul>
    3. 3. PHP on IBM i - History <ul><li>As of V5R2 (approx. 2003), IBM i developers have had the ability to compile and run PHP and MySQL in the PASE environment. </li></ul><ul><li>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. </li></ul><ul><li>February 2009 – New IBM i shipments come preloaded with Zend Core PHP. </li></ul>
    4. 4. Why PHP on IBM i? <ul><li>Easy to make the transition from RPG to PHP. </li></ul><ul><li>Do not need to know object-oriented techniques. </li></ul><ul><li>Most popular web development language. </li></ul><ul><li>Huge open source community with vast amount of sample code and documentation. </li></ul><ul><li>Affordability (Did we mention that Zend Core and Zend Studio for i5/OS are free?) </li></ul><ul><li>Extensions for most common applications. </li></ul><ul><li>Many more… </li></ul>
    5. 5. Zend Core for i5/OS <ul><li>Allows PHP applications to access: </li></ul><ul><li>DB2 using RPG-like database access functions </li></ul><ul><li>Native RPG, Cobol, C and CL program calls </li></ul><ul><li>Native commands </li></ul><ul><li>Spool files </li></ul><ul><li>Data areas </li></ul><ul><li>User spaces </li></ul><ul><li>System values </li></ul><ul><li>Data queues </li></ul><ul><li>Message queues </li></ul><ul><li>Job Logs </li></ul>
    6. 6. Value-Add for IBM i <ul><li>By running PHP applications on the IBM i you gain the security, stability and reliability that the IBM i is known for. </li></ul><ul><li>Quickly and easily implement new applications. </li></ul><ul><ul><li>Open Source applications </li></ul></ul><ul><ul><li>Existing sample code </li></ul></ul><ul><li>Leverage existing business logic. For example RPG & Cobol programs. </li></ul><ul><li>Cost effective web solution (did we mention its free?) </li></ul><ul><li>Does not add overhead like some other solutions. </li></ul>
    7. 7. Access IBM i DB2 tables with PHP <ul><li>IBM DB2 functions </li></ul><ul><ul><li>Completely system independent </li></ul></ul><ul><li>Zend Toolkit Class library – Native File access i5_xxxx </li></ul><ul><ul><li>Provides ready access to IBM i DB2 tables </li></ul></ul><ul><ul><li>Eases transition from RPG to PHP </li></ul></ul><ul><li>MySQL IBMDB2i storage engine </li></ul><ul><ul><li>Allows for quickly porting open source applications to DB2 database. </li></ul></ul><ul><ul><li>Provides an easy way to prototype IBM i PHP applications without access to an IBM i. </li></ul></ul>
    8. 8. How to start <ul><li>Install Zend Core and/or Zend Platform on your IBM i (Check, it might already be there.) </li></ul><ul><li>Start the Zend Core Subsystem and Apache Servers. </li></ul><ul><li>Install Zend Studio (or another IDE) on a Windows client. </li></ul><ul><li>Get on the internet and download some open source examples and/or simple applications. </li></ul><ul><li>Save the sample code in the htdocs directory on your IBM i. </li></ul><ul><li>Open a browser and enter the URL. </li></ul><ul><li>That’s it! </li></ul>
    9. 9. Questions?
    10. 10. IBM i DB2 sample <ul><li><?php </li></ul><ul><li>// Set the database name. </li></ul><ul><li>// This is an IBM i System table (it exists on all IBM i machines) </li></ul><ul><li>$tableName = 'SYSTABLES'; </li></ul><ul><li>$libName = 'QSYS2'; </li></ul><ul><li>// create the connection to the IBM i relational database </li></ul><ul><li>if (!$dbh = db2_connect(“localhost&quot;,“jolen&quot;,“pass123&quot;)) { </li></ul><ul><li>echo &quot;connection failed.<br>&quot;; </li></ul><ul><li>echo db2_conn_errormsg() . &quot;<br>&quot;; </li></ul><ul><li>die(); </li></ul><ul><li>} </li></ul><ul><li>// Retrieve a resultset of the column info for the specified table </li></ul><ul><li>if (!$cols = db2_columns( $dbh, null, $libName, $tableName, '%' )) { </li></ul><ul><li>echo &quot;columns retrieval failed.<br>&quot;; </li></ul><ul><li>echo db2_stmt_errormsg() . &quot;<br>&quot;; </li></ul><ul><li>die(); </li></ul><ul><li>} </li></ul><ul><li>// output the Library and name of the table </li></ul><ul><li>$column = db2_fetch_assoc($cols); </li></ul><ul><li>echo &quot;Table: &quot;; </li></ul><ul><li>echo $column[&quot;TABLE_SCHEM&quot;].&quot;/&quot;.$column[&quot;TABLE_NAME&quot;].&quot;<br>&quot;; </li></ul><ul><li>// output all the column names </li></ul><ul><li>do { </li></ul><ul><li>echo $column[&quot;COLUMN_NAME&quot;].&quot;<br>&quot;; </li></ul><ul><li>} while ($column = db2_fetch_assoc($cols)); </li></ul><ul><li>db2_close($dbh); </li></ul><ul><li>?> </li></ul>
    11. 11. IBM i DB2 sample output
    12. 12. IBM DB2 Function sample <ul><li>Source name: displayColumns.php </li></ul><ul><li><?php </li></ul><ul><li>function displayColumns( $libraryName, $tableName ) { </li></ul><ul><li>if (!isset($dbh)) { </li></ul><ul><li>$dbh = db2_connect(&quot;localhost&quot;, &quot;jolen&quot;, &quot;pass123&quot;); </li></ul><ul><li>if (!$dbh) { </li></ul><ul><li>echo &quot;connection failed.<br>&quot;; </li></ul><ul><li>echo db2_conn_errormsg() . &quot;<br>&quot;; </li></ul><ul><li>die(); </li></ul><ul><li>} </li></ul><ul><li>} </li></ul><ul><li>// retrieve a result set with the column info for the </li></ul><ul><li>// file specified at the top of the script. </li></ul><ul><li>if (!$cols = db2_columns( $dbh, null, $libraryName, $tableName, '%' )) { </li></ul><ul><li>echo &quot;columns retrieval failed.<br>&quot;; </li></ul><ul><li>echo db2_stmt_errormsg() . &quot;<br>&quot;; </li></ul><ul><li>die(); </li></ul><ul><li>} </li></ul><ul><li>// Fetch the first row and output the file name and library name from the result set. </li></ul><ul><li>$column = db2_fetch_assoc($cols); </li></ul><ul><li>echo &quot;Table: &quot;; </li></ul><ul><li>echo $column[&quot;TABLE_SCHEM&quot;].&quot;/&quot;.$column[&quot;TABLE_NAME&quot;].&quot;<br>&quot;; </li></ul><ul><li>// loop thru all the result set rows and list all the column names. </li></ul><ul><li>do { </li></ul><ul><li>echo $column[&quot;COLUMN_NAME&quot;].&quot;<br>&quot;; </li></ul><ul><li>} while ($column = db2_fetch_assoc($cols)); </li></ul><ul><li>} </li></ul>
    13. 13. IBM DB2 Function sample <ul><li><?php </li></ul><ul><li>require_once(‘displayColumns.php'); </li></ul><ul><li>displayColumns( 'QSYS2', 'SYSTABLES' ); </li></ul><ul><li>echo &quot;<br><br>&quot;; </li></ul><ul><li>displayColumns( 'QSYS2', 'SYSROUTINES' ); </li></ul><ul><li>?> </li></ul>
    14. 14. IBM DB2 Class example <ul><li>Source name: fileinfo.class.php </li></ul><ul><li><?php </li></ul><ul><li>class tableInfo { </li></ul><ul><li>var $columns; </li></ul><ul><li>var $table; </li></ul><ul><li>var $library; </li></ul><ul><li>var $dbh; </li></ul><ul><li>function __construct( $libraryName, $tableName ) { </li></ul><ul><li>if (!isset($this->dbh)) { </li></ul><ul><li>$this->dbh = db2_connect(&quot;localhost&quot;, &quot;jolen&quot;, &quot;pass123&quot;); </li></ul><ul><li>if (!$this->dbh) { </li></ul><ul><li>echo &quot;connection failed.<br>&quot;; </li></ul><ul><li>echo db2_conn_errormsg() . &quot;<br>&quot;; </li></ul><ul><li>die(); </li></ul><ul><li>} </li></ul><ul><li>} </li></ul><ul><li>$this->library = $libraryName; </li></ul><ul><li>$this->table = $tableName; </li></ul><ul><li>} </li></ul>
    15. 15. <ul><li>// retrieve a result set with the column info for the file specified at the top of the script . </li></ul><ul><li>function retrieveColumnInfo() { </li></ul><ul><li>if (!$this->columns = db2_columns( $this->dbh, null, $this->library, $this->table, '%' )) { </li></ul><ul><li>echo &quot;columns retrieval failed.<br>&quot;; </li></ul><ul><li>echo db2_stmt_errormsg() . &quot;<br>&quot;; </li></ul><ul><li>die(); </li></ul><ul><li>} </li></ul><ul><li>} // end of function </li></ul><ul><li>// retrieve a result set with the column info for the file specified at the top of the script . </li></ul><ul><li>function displayColumnInfo () { </li></ul><ul><li>echo &quot;Table: &quot;; </li></ul><ul><li>echo $this->library.&quot;/&quot;.$this->table.&quot;<br>&quot;; </li></ul><ul><li>$firstpass = TRUE; </li></ul><ul><li>while ($column = db2_fetch_assoc($this->columns)) { </li></ul><ul><li>if ($firstpass) { </li></ul><ul><li>$firstpass = FALSE; </li></ul><ul><li>echo &quot;<table border=1><tr>&quot;; </li></ul><ul><li>foreach ($column as $key => $value) { </li></ul><ul><li>echo &quot;<th>&quot;.$key.&quot;</th>&quot;; </li></ul><ul><li>} </li></ul><ul><li>echo &quot;</tr>&quot;; </li></ul><ul><li>} </li></ul><ul><li>echo &quot;<tr>&quot;; </li></ul><ul><li>foreach ($column as $value) { </li></ul><ul><li>echo &quot;<td>&quot;.$value.&quot;</td>&quot;; </li></ul><ul><li>} </li></ul><ul><li>echo &quot;</tr>&quot;; </li></ul><ul><li>} </li></ul><ul><li>echo &quot;</table>&quot;; </li></ul><ul><li>} // end of function </li></ul><ul><li>} // end of class code </li></ul>IBM DB2 Class example Continued
    16. 16. <ul><li><?php </li></ul><ul><li>require_once(‘fileinfo.class.php'); </li></ul><ul><li>$sysTables = new tableInfo('QSYS2','SYSTABLES'); </li></ul><ul><li>$sysRoutines = new tableInfo('QSYS2','SYSROUTINES'); </li></ul><ul><li>$sysRoutines->retrieveColumnInfo(); </li></ul><ul><li>$sysRoutines->displayColumnInfo(); </li></ul><ul><li>$sysTables->retrieveColumnInfo(); </li></ul><ul><li>$sysTables->displayColumnInfo(); </li></ul><ul><li>?> </li></ul>IBM DB2 Class example
    17. 17. Questions?
    18. 18. Important Links <ul><li>IBMDB2i storage engine install and docs: </li></ul><ul><li>http://solutions.mysql.com/engines/ibm_db2_storage_engine.html </li></ul><ul><li>IBM Redbook on IBMDB2i: </li></ul><ul><li>http://www.redbooks.ibm.com/abstracts/sg247705.html?Open </li></ul><ul><li>PHP Extensions </li></ul><ul><li>http://pecl.php.net </li></ul><ul><li>IBMDB2 documentation </li></ul><ul><li>http://www.php.net/ibm_db2 </li></ul><ul><li>Subversion source control </li></ul><ul><li>http://subversion.tigris.org </li></ul><ul><li>Subclipse – subversion Eclipse Team Provider plug-in (works with RDi/WDSc) </li></ul><ul><li>http://subclipse.tigris.org </li></ul>
    19. 19. OPC – 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
    20. 20. Next steps <ul><li>Training </li></ul><ul><ul><li>Zend training classes </li></ul></ul><ul><ul><li>Olen Business Consulting, Inc. training (insert shameless sales pitch here) </li></ul></ul><ul><ul><li>Personalized training on-site </li></ul></ul><ul><li>Source control/Version control </li></ul><ul><ul><li>Subversion can be installed on IBM i </li></ul></ul><ul><ul><li>Subclipse plug-in works with WDSc/RDi </li></ul></ul><ul><li>Database abstraction </li></ul><ul><ul><li>DAO, VO and PDO </li></ul></ul><ul><ul><li>OO Classes </li></ul></ul><ul><li>Object-oriented coding </li></ul><ul><ul><li>Not necessary to begin using PHP </li></ul></ul><ul><ul><li>You will rapidly see the advantages once you get comfortable with PHP </li></ul></ul><ul><li>Zend Framework and Zend Platform </li></ul><ul><li>Certification </li></ul>
    21. 21. Questions?