Introduction to PHP 5 and IBM DB2 Building web applications with PHP 5.2 and IBM DB2.

Slides:



Advertisements
Similar presentations
Connecting to Databases. connecting to DB DB server typically a standalone application Server runs on localhost for smaller sites –i.e. Same machine as.
Advertisements

Connecting to Databases. relational databases tables and relations accessed using SQL database -specific functionality –transaction processing commit.
UFCE8V-20-3 Information Systems Development 3 (SHAPE HK)
® IBM Software Group © IBM Corporation QUY Thai Duy – ITFac DLU Lesson 16: Java, Ruby on Rails, PHP.
Data Access Worldwide May 16 – 18, 2007 Copyright 2007, Data Access Worldwide May 16 – 18, 2007 Copyright 2007, Data Access Worldwide Standardizing Application.
Software Freedom Day th September 2007 Asia Pacific Institute of Information Technology Colombo, Sri Lanka. Nazly Ahmed Scripting The Web.
PHP: Hypertext Preprocessor Greg Lowe Rob White Brian Wright Mike Zywiec.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 13 Introduction to SQL Programming Techniques.
PHP/ASP Robert Nelson & Will Vanlue BA370 November 4 th, 2005.
By Brian Patterson & Amanda Perez. PHP was originally created to maintain his personal homepage, hence the name PHP. Development began in 1994 and was.
PHP Scripting Language. Introduction “PHP” is an acronym for “PHP: Hypertext Preprocessor.” It is an interpreted, server-side scripting language. Originally.
An Introduction to PHP Data Objects A Better Way to Interact with Your Database by Rusty Keele.
WHAT IS PHP PHP is an HTML-embedded scripting language primarily used for dynamic Web applications.
PHP PHP: Hypertext Preprocessing. What is PHP? PHP is a server-side scripting language designed specifically for the Web. An open source language PHP.
Introducing PHP Data Objects Wez Furlong
1 Web Database Processing. Web Database Applications Static Report Publishing a report is prepared from a database application and exported to HTML DB.
Getting connected.  Java application calls the JDBC library.  JDBC loads a driver which talks to the database.  We can change database engines without.
What is PHP PHP (officially "PHP: Hypertext Preprocessor") is a server-side HTML-embedded scripting language –means that code does not need to be compiled.
PHP - Hypertext Preprocessor Yaron Benita De Paul University.

PHP and SQL/J Pertemuan 12 Matakuliah: T0413 Tahun: 2009.
PHP was created by Rasmus Lerdorf in It was initially server-side, traffic tracking script. PHP 2 (1995) Added database support, file uploads, regular.
PHP Data Object (PDO) Khaled Al-Sham’aa. What is PDO? PDO is a PHP extension to formalise PHP's database connections by creating a uniform interface.
PHP Data Objects Layer (PDO) Ilia Alshanetsky. What is PDO Common interface to any number of database systems. Common interface to any number of database.
Sayed Ahmed Computer Engineering, BUET, Bangladesh MSC, Computer Science, U of Manitoba, Canada
Theory and practice of computer technologies used for creating DEA software Eugene P. MORGUNOV Siberian State Aerospace University Krasnoyarsk, Russia.
PHP PHP: Hypertext Preprocessing Preston Brinks and Sean McKenzie.
Jordan Bruce I07 – Open Source and IDS Major Canadian Retail Drugstore’s Prescription For Success Tuesday 3 rd October :15 – 16:15.
PHP With the New PDO::Informix Presented by: Thomas Beebe Advanced DataTools Corporation
Codeigniter is an open source web application. It occupies a very small amount of space in the memory and is most useful for developers who aim to develop.
PHP With Oracle 11g XE By Shyam Gurram Eastern Illinois University.
What is MySQLi? Since the mid-90s, Mysql extension has served as the major bridge between PHP and MySQL. Although it has performed its duty quite well,
MySQL™: The Open Source Database for Mission-Critical, Heavy Load Applications Kaj Arnö, VP Training, MySQL AB Stuttgart, Germany Belgrad, Serbia.
Chapter 6 PHP Interacts with Mysql Database. Introduction In PHP, there is no consolidated interface. Instead, a set of library functions are provided.
Lecture 10 – MYSQL and PHP (Part 2)
Introduction to PHP and MySQL Kirkwood Center for Continuing Education By Fred McClurg, © Copyright 2015, Fred McClurg, All Rights.
PHP Features. Features Clean syntax. Object-oriented fundamentals. An extensible architecture that encourages innovation. Support for both current and.
1Computer Sciences Department Princess Nourah bint Abdulrahman University.
Accessing Your MySQL Database from the Web with PHP (Ch 11) 1.
PHP PDO & PHP SOAP Introduce. Agenda What is PHP PDO and PHP SOAP? Setup PHP PDO to connect database, query database and close the connection. Setup SOAP.
WEB DEVELOPMENT WITH PHP/MYSQL. WEB DEVELOPMENT COURSE HAS DIFFERENT NAME IN DIFFERENT INSITUTES, THIS IS A CORE COURSE FOR BS/MS STUDENTS. THIS IS ALSO.
PHP Data Objects Wez Furlong. About the author PHP Core Developer since 2001 Author of the Streams layer “King” of PECL Author of most of PDO and its.
PHP Workshop ‹#› PHP Data Object (PDO). PHP Workshop ‹#› What is PDO? PDO is a PHP extension to formalise PHP's database connections by creating a uniform.
PHP Workshop ‹#› أطلق إبداعك 2 أطلق إبداعك 2 مدرس معتمد من مركز زووم PHP Data Object (PDO)
PHP Introduction PHP is a server-side scripting language.
CHAPTER 10 PHP MySQL Database
1Introduction to PHP 5 Presented by Brett Buddin.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 14 Web Database Programming Using PHP.
Fundamentals of Web DevelopmentRandy Connolly and Ricardo HoarFundamentals of Web DevelopmentRandy Connolly and Ricardo Hoar Fundamentals of Web DevelopmentRandy.
Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe.
PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages. PHP is a widely-used, free, and efficient alternative.
Introduction to PHP. PHP Origins Rasmus LerdorfRasmus Lerdorf (born Greenland, ed Canada) PHP originally abbreviation for ‘Personal Home Pages’, now ‘PHP.
Enterprise PHP PHP applications in the big business.
Web Systems & Technologies
2nd year Computer Science & Engineer
Introduction to PHP and MySQL – Creating Database-Driven Websites
PHP Data Objects for MySQL
Accessing the Database Server: ODBC, OLE DB, and ADO
Open Source distributed document DB for an enterprise
Advanced Web Automation Using Selenium
Introduction to PHP “PHP is a server-side scripting language designed specifically for the Web. Within an HTML page, you can embed PHP code that will be.
Introduction to PHP “PHP is a server-side scripting language designed specifically for the Web. Within an HTML page, you can embed PHP code that will be.
PHP PHP PHP STAND FOR HYPERTEXT PRE-PROCESSOR. PHP PHP PHP STAND FOR HYPERTEXT PRE-PROCESSOR.
Multitier Architecture, MySQL & PHP
PHP / MySQL Introduction
Tutorial 6 PHP & MySQL Li Xu
Web Programming– UFCFB Lecture
Introduction to PHP.
PHP Forms and Databases.
Web Application Development Using PHP
Presentation transcript:

Introduction to PHP 5 and IBM DB2 Building web applications with PHP 5.2 and IBM DB2

2 „PHP 5 and IBM DB2“ © Thorsten Rinne 2006 Overview ❙ From Personal Homepage Tools to PHP 5.2 ❙ PHP 5.2 and databases ❙ What‘s new in PHP 5.2 ? ❙ PDO: PHP Data Objects ❙ Why IBM DB2 ? ❙ PHP and IBM DB2 ❙ Introduction of ibm_db2 extension ❙ Functions and special features

3 „PHP 5 and IBM DB2“ © Thorsten Rinne 2006 About the presenter ❙ Thorsten Rinne ❙ Born in 1977 ❙ Graduated in computer sciences ❙ Software developer at Mayflower GmbH / ThinkPHP, Munich, Germany ❙ Rating and reporting applications ❙ Business critical bank applications ❙ 1999: started PHP programming ❙ 2001: started the development with the open source FAQ management software phpMyFAQ ( ❙ 2002: first contact with IBM DB2 ❙ 2005: porting phpMyFAQ to IBM DB2

4 „PHP 5 and IBM DB2“ © Thorsten Rinne 2006 From Personal Homepage Tools to PHP 5.2 ❙ Released as a collection of some Perl scripts in 1995 by Rasmus Lerdorf, called „Personal Homepage Tools“. ❙ 1997: PHP/FI was rewritten in C ❙ PHP 3 with simple features of object orientation and a new core by Zeev Suraski and Andi Gutmans was released 1998 ❙ In 2000 PHP 4 was released with better object orientation and Zend Engine 1 ❙ 2004: PHP 5.0 brought many missing features for object orientated programming ❙ PHP 5.2 was released in November 2006 ❙ In development: PHP 6 with unicode support

5 „PHP 5 and IBM DB2“ © Thorsten Rinne 2006 What‘s new in PHP 5.2 ? ❙ New filter and JSON extension ❙ Object orientated zip extension ❙ Improved memory manager ❙ Improved PDO and SPL methods ❙ Added new functions ❙ Fixed many bugs

6 „PHP 5 and IBM DB2“ © Thorsten Rinne 2006 PHP and databases: Basics ❙ PHP supports all important database interfaces: ❙ MySQL ❙ PostgreSQL ❙ MS SQL server ❙ Oracle ❙ SQLite ❙ Firebird / Interbase ❙ Sybase ❙ Informix ❙ ODBC ❙ …and IBM DB2 ❙ But: every database needs its own extention!

7 „PHP 5 and IBM DB2“ © Thorsten Rinne 2006 PHP and databases: PHP 5.2 ❙ PDO features a common and efficient interface ❙ Special extensions like MYSQLi ❙ Ready for PEAR ❙ Support for ❙ File based databases like SQLite ❙ Connection with internal and external database servers ❙ ODBC

8 „PHP 5 and IBM DB2“ © Thorsten Rinne 2006 Introduction of PDO ❙ Abstraction of the data access (standard API) ❙ Plugins for various database systems ❙ Object-orientated ❙ Support for PHP iterators ❙ Very fast because of the C implemention ❙ PDO… ❙ … drivers are available in PECL since PHP 5.0 ❙ … is part of the PHP core since version 5.1 ❙ … delivers pre-compiled Windows DLLs

9 „PHP 5 and IBM DB2“ © Thorsten Rinne 2006 Features of PDO ❙ Prepared statements ❙ SQL error codes ❙ Database portability features ❙ Support for transactions ❙ Scrollable cursors ❙ Support for PHP error handling and PHP exceptions ❙ Planned for a future release: support for LOBs

10 „PHP 5 and IBM DB2“ © Thorsten Rinne 2006 Using PDO prepare('SELECT * FROM faquser'); $stmt->setFetchMode(PDO::FETCH_NAMED); $stmt->execute(); while ($row = $stmt->fetch()) { print $row. " "; } $db = null; } catch (PDOException $e) { print "Error: ". $e->getMessage(). " "; die(); }

11 „PHP 5 and IBM DB2“ © Thorsten Rinne 2006 Why using IBM DB2 ? ❙ IBM DB2 is the database for enterprise applications ❙ Available for z/OS, iSeries, Linux, UNIX, and Windows ❙ Highly scalable ❙ Starts with IBM DB2 Express-C for 2 CPUs ❙ Available for systems with more than 64 processors ❙ Clustered stystems up to 1024 nodes ❙ Performance leader on Linux (TPC-H) ❙ Current version: IBM DB2 V.9.1 ❙ for relational and XML data ❙ SQL queries und XQuery ❙ SAP certified

12 „PHP 5 and IBM DB2“ © Thorsten Rinne 2006 IBM DB2 in the net Internet/Intranet Webbrowser DB2 client PHP / Webserver DB2 (Linux, iSeries, pSeries) DB2 (z/OS) DB2 Connect

13 „PHP 5 and IBM DB2“ © Thorsten Rinne 2006 PHP and IBM DB2 ❙ PHP offers four possibilities: ❙ ODBC (ext/odbc) ❙ The ibm_db2 extension for IBM DB2, IBM Cloudscape, and Apache Derby ❙ PDO_ODBC ❙ PDO_IBM (in development, no documentation) ❙ Open source software ❙ Download:

14 „PHP 5 and IBM DB2“ © Thorsten Rinne 2006 PHP and IBM DB2: ODBC (ext/odbc) ❙ PHP core extension ❙ Typically compiled against the generic ODBC driver ❙ Can be compiled against the IBM DB2 client library (./configure --with-ibm-db2) ❙ Disadvantages: ❙ Scrollable cursors are very slow ❙ No support for IN/INOUT stored procedures

15 „PHP 5 and IBM DB2“ © Thorsten Rinne 2006 PHP and IBM DB2: ibm_db2 (ext/ibm_db2) ❙ Download source code and binaries from PECL repository ❙ Developed and supported by IBM ❙ Full support for stored procedures and LOBs ❙ Very fast because of its C implementation! ❙ Disadvantage: ❙ Complete new extension ❙ Not 100% free of bugs

16 „PHP 5 and IBM DB2“ © Thorsten Rinne 2006 PHP and IBM DB2: PDO_ODBC ❙ Fast, easy and C based standard interface for PHP ❙ PDO_ODBC will be compiled against the generic IBM DB2 libraries ❙ Standard API for better software development ❙ Fast and object orientated interface ❙ Disadvantages: ❙ Only for PHP 5.x and later ❙ Still in development

17 „PHP 5 and IBM DB2“ © Thorsten Rinne 2006 First contact with ext/ibm_db2 ?"; $conn = db2_connect($database, $user, $password); $stmt = db2_prepare($conn, $sql); $res = db2_execute($stmt, array(0)); while ($row = db2_fetch_assoc($stmt)) { print ' '. $row['REALNAME']. ' '; print $row[' ']. ' '; }

18 „PHP 5 and IBM DB2“ © Thorsten Rinne 2006 What‘s happening ? ❙ The first connection takes a long time … ❙ With the first connection DB2 binds some system resources ❙ Solution: ACTIVATE DATABASE faq ❙ Persistent connections? Be careful, but really great in read mode

19 „PHP 5 and IBM DB2“ © Thorsten Rinne 2006 Closing the first connection ❙ Automatic disconnection after PHP script execution ❙ Explicit disconnection with: db2_close($conn); ?>

20 „PHP 5 and IBM DB2“ © Thorsten Rinne 2006 Error handling with ibm_db2 ❙ SQLSTATE return values ❙ db2_conn_error() ❙ db2_stmt_error() ❙ SQL error message ❙ db2_conn_errormsg() ❙ db2_stmt_errormsg()

21 „PHP 5 and IBM DB2“ © Thorsten Rinne 2006 Prepared statements with ibm_db2 ❙ The ibm_db2 extension supports prepared statements ❙ The values are binded at their position with the placeholder „?“: $sql = "SELECT id FROM faquser WHERE realname = '?'"; $stmt = db2_prepare($conn, $sql); $res = db2_execute($stmt, array('Thorsten Rinne'));

22 „PHP 5 and IBM DB2“ © Thorsten Rinne 2006 Fetching data by row ❙ The column number is the index: $row = db2_fetch_array($stmt); // $row[0] ❙ The column name is the index: $row = db2_fetch_assoc($stmt); // $row['COLUMN_NAME'] ❙ The column number and the name are the index: $row = db2_fetch_both($stmt); ❙ PHP object, column names are object properties: $row = db2_fetch_object($stmt); // $row->COLUMN_NAME

23 „PHP 5 and IBM DB2“ © Thorsten Rinne 2006 Differences to MySQL (I) ❙ IBM DB2 does not return the number of affected rows for SELECT statements ❙ Solutions: ❙ Slow: Scrollable Cursors $stmt = db2_exec($conn, "SELECT realname FROM faquser", array('cursor' => DB2_SCROLLABLE)); $num = db2_num_rows($stmt); ❙ Better: $stmt = db2_exec($conn, "SELECT COUNT(*) FROM faquser"); list($num) = db2_fetch_array($stmt); ❙ The best: $stmt = db2_exec($conn, "SELECT realname, realname FROM faquser"); while ($row = db2_fetch_assoc($stmt)) { … }

24 „PHP 5 and IBM DB2“ © Thorsten Rinne 2006 Differences to MySQL (II) ❙ IBM DB2 supports no LIMIT ❙ Solutions ❙ ROW_NUMBER OVER() syntax (ANSI SQL) ❙ Scrollable cursors ❙ Sequences and auto-generated columns for easy WHERE clauses ❙ Column names are always UPPERCASE: print $row['REALNAME']; print $row['realname']; // Notice!

25 „PHP 5 and IBM DB2“ © Thorsten Rinne 2006 Using XQuery in V.9.1 ❙ IBM DB2 V.9.1 can save XML data ❙ Example: $xquery = '$document/costumer/phone'; $res = db2_exec($conn, "SELECT XMLQUERY('$xquery' PASSING INFO AS \“document\") FROM COSTUMER");

26 „PHP 5 and IBM DB2“ © Thorsten Rinne 2006 Any questions? ???

Thanks for your attention! Thorsten Rinne, Dipl.-Inf. (FH) Mayflower GmbH Sendlinger Str. 42a D Munich Germany +49 (89) – 31