1 / 21

Why PHP on IBM i

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.

Download Presentation

Why PHP on IBM i

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  2. 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”

  3. PHP 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.

  4. 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…

  5. Zend 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

  6. 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.

  7. Access IBM i DB2 tables with PHP • 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.

  8. 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!

  9. Questions?

  10. IBM 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 database if (!$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 table if (!$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 names do { echo $column["COLUMN_NAME"]."<br>"; } while ($column = db2_fetch_assoc($cols)); db2_close($dbh); ?>

  11. IBM i DB2 sample output

  12. IBM DB2 Function sample Source name: displayColumns.php <?php function 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)); }

  13. IBM DB2 Function sample <?php require_once(‘displayColumns.php'); displayColumns( 'QSYS2', 'SYSTABLES' ); echo "<br><br>"; displayColumns( 'QSYS2', 'SYSROUTINES' ); ?>

  14. IBM DB2 Class example Source 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; }

  15. IBM DB2 Class example Continued // 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

  16. IBM DB2 Class example <?php require_once(‘fileinfo.class.php'); $sysTables = new tableInfo('QSYS2','SYSTABLES'); $sysRoutines = new tableInfo('QSYS2','SYSROUTINES'); $sysRoutines->retrieveColumnInfo(); $sysRoutines->displayColumnInfo(); $sysTables->retrieveColumnInfo(); $sysTables->displayColumnInfo(); ?>

  17. Questions?

  18. Important Links IBMDB2i 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 Extensions http://pecl.php.net IBMDB2 documentation http://www.php.net/ibm_db2 Subversion source control http://subversion.tigris.org Subclipse – subversion Eclipse Team Provider plug-in (works with RDi/WDSc) http://subclipse.tigris.org

  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. Next 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

  21. Questions?

More Related