You are previewing PHP Oracle Web Development.
O'Reilly logo
PHP Oracle Web Development

Book Description

A practical guide to combining the power, performance, scalability, and reliability of the Oracle Database with the ease of use, short development time, and high performance of PHP

  • Program your own PHP/Oracle application

  • Move data processing inside the database

  • Distribute data processing between the web/PHP and Oracle database servers

  • Create reusable building blocks for PHP/Oracle solutions

  • Use up-to-date technologies, such as Ajax and web services, in PHP Oracle development

  • In Detail

    Oracle Database gets high marks for performance, reliability, and scalability. Building and deploying your PHP applications on Oracle Database enables you to combine the power and robustness of Oracle and the ease of use, short development time, and high performance of PHP. When used in a complementary way, PHP and Oracle allow you to build high-performance, scalable, and reliable data-driven Web applications with a minimum of effort.

    When building a PHP/Oracle application, you have two general options. The first is to use an Oracle database just to store data, performing all the operations on that data on the client side; the other is to use the database not only to store data, but also to process it, thus moving data processing to the data. While building the key business logic of a database-driven PHP application inside the database is always a good idea, you should bear in mind that not all of the databases available today allow you to do. The Oracle database, which offers record-breaking performance, scalability, and reliability, does. The partnership of Oracle and the open-source scripting language PHP is an excellent solution for building high-performance, scalable, and reliable data-driven web applications.

    This 100% practical book is crammed full of easy-to-follow examples. It provides all the tools a PHP/Oracle developer needs to take advantage of the winning combination. It addresses the needs of a wide spectrum of PHP/Oracle developers, placing the emphasis on the most up-to-date topics, such as new PHP and Oracle Database features, stored procedure programming, handling transactions, security, caching, web services, and Ajax.

    This practical book is built entirely around example code, covering the most popular and up-to-date topics on using PHP in conjunction with Oracle. The book explains in extensive detail how to build robust, efficient, and secure PHP/Oracle solutions.

    Table of Contents

    1. PHP Oracle Web Development
    2. Credits
    3. About the Author
    4. About the Reviewer
    5. Preface
      1. What This Book Covers
      2. Who is This Book For?
      3. Conventions
      4. Reader Feedback
      5. Customer Support
        1. Downloading the Example Code for the Book
        2. Errata
        3. Questions
    6. 1. Getting Started with PHP and Oracle
      1. Why PHP and Oracle?
        1. Simplicity and Flexibility
        2. Performance
        3. Robustness
      2. Exploring PHP and Oracle Alternatives
        1. PHP and MySQL
        2. JSF and Oracle
      3. What You Need to Start
        1. Pieces of Software Required
        2. Oracle Database Considerations
          1. Understanding the Oracle Database
          2. Choosing Between Oracle Database Editions
          3. Obtaining Oracle Database Software
        3. PHP Considerations
          1. Apache HTTP Server
          2. Why PHP 5
          3. Obtaining PHP
        4. Making PHP and Oracle Work Together
          1. Oracle Instant Client
          2. Zend Core for Oracle
        5. Using Oracle SQL*Plus
          1. Why Use SQL*Plus in PHP/Oracle Development?
          2. Connecting to a Database with SQL*Plus
          3. Running Scripts in SQL*Plus
        6. Putting It All Together
      4. Creating Your First PHP/Oracle Application
        1. Connecting to a Database
          1. Using the Local Naming Method
          2. Using the Easy Connect Method
        2. Issuing an SQL Statement Against the Database
        3. Fetching and Displaying Results
      5. Summary
    7. 2. PHP and Oracle Connection
      1. Introducing the PHP OCI8 Extension
        1. Why Use OCI8 Extension
        2. Processing SQL Statements with OCI8
      2. Connecting to Oracle with OCI8
        1. Defining a Connection String
        2. OCI8 Functions for Connecting to Oracle
      3. Parsing and Executing SQL Statements with OCI8
        1. Preparing SQL Statements for Execution
        2. Using Bind Variables
        3. Executing SQL Statements
        4. Handling Errors
          1. Using the oci_error Function
          2. Using the trigger_error Function
          3. Using Exceptions
      4. Fetching Results with OCI8
        1. OCI8 Functions for Fetching
        2. Fetching the Next Row
        3. Fetching All the Rows
      5. Alternatives to PHP OCI8 Extension
        1. Using PEAR DB
        2. Using ADOdb
        3. Using PDO
        4. Creating Your Own Library on Top of OCI8
      6. Summary
    8. 3. Data Processing
      1. Implementing the Business Logic of a PHP/Oracle Application
        1. When to Move the Data to the Processing
        2. Advantages of Moving the Processing to the Data
        3. Ways of Implementing Business Logic Inside the Database
        4. Interaction between Components Implementing Business Logic
      2. Using Complex SQL Statements
        1. Employing Oracle SQL Functions in Queries
          1. Oracle SQL Functions versus PHP Data Processing
          2. Aggregate Functions
          3. The GROUP BY Clause
        2. Using Join Queries
        3. Taking Advantage of Views
          1. The Key Benefits of Using Views
          2. Hiding Data Complexity with Views
          3. Using the WHERE Clause
      3. Using Stored Subprograms
        1. What are Stored Subprograms?
        2. Advantages of Stored Subprograms
        3. An Example of When to Use a Stored Subprogram
        4. Creating Stored Subprograms
        5. Calling Stored Subprograms from PHP
      4. Using Triggers
        1. Creating Triggers
        2. Firing Triggers
        3. Calling Stored Procedures from a Trigger
      5. Summary
    9. 4. Transactions
      1. Overview of Transactions
        1. What is a Transaction?
        2. What are ACID Rules?
        3. How Transactions Work in Oracle
        4. Using Transactions in PHP/Oracle Applications
        5. Structuring a PHP/Oracle Application to Control Transactions
      2. Developing Transactional Code
        1. Controlling Transactions from PHP
        2. Moving Transactional Code to the Database
          1. Using Triggers
          2. Dealing with Statement-Level Rollbacks
      3. Transaction Isolation Considerations
        1. What OCI8 Connection Function to Choose
        2. Concurrent Update Issues
          1. Locking Issues
          2. Lost Updates
        3. Autonomous Transactions
      4. Summary
    10. 5. Object-Oriented Approach
      1. Implementing PHP Classes to Interact with Oracle
        1. Building Blocks of Applications
          1. Creating a Custom PHP Class from Scratch
          2. Testing the Newly Created Class
          3. Taking Advantage of PHP 5's Object-Oriented Features
        2. Functionality and Implementation
        3. Reusability
        4. Handling Exceptions
          1. Modifying an Existing Class to use Exceptions
          2. Distinguishing between Different Error Types
          3. Are Exceptions Necessarily Errors?
      2. Extending Existing Classes
        1. Using Standard Classes
          1. PEAR::Auth in Action
          2. Securing Pages with PEAR::Auth
        2. Customizing Standard Classes
          1. Customizing PEAR::Auth
          2. Building More Compact Client Code
      3. Interactions between Objects
        1. Composition
        2. Aggregation
      4. Event-Driven Communication
      5. Using Oracle Object-Relational Features
        1. Using Oracle Object Types
        2. Implementing Business Logic with Methods of Oracle Objects
        3. Using Oracle Objects to Simplify Application Creation
      6. Summary
    11. 6. Security
      1. Securing PHP/Oracle Applications
        1. Authenticating Users
        2. Separating Security Management and Data
          1. Using Two Database Schemas to Improve Security
          2. Using Three Database Schemas to Improve Security
          3. Employing PL/SQL Packages and Table Functions to Securely Access Database Data
          4. Using the %ROWTYPE Attribute
          5. Building a Custom Storage Container for the PEAR::Auth Class
          6. Testing the Authentication System
        3. Performing Authorization Based on the User Identity
          1. Using Sessions to Hold Information about the Authenticated User
          2. Holding a User's Information in Package Variables
          3. Protecting Resources Based on Information about the Authenticated User
      2. Hashing
        1. Hashing Passwords
        2. Modifying an Authentication System to Use Hashing
      3. Setting Up Fine-Grained Access with Database Views
        1. Implementing Column-Level Security with Views
        2. Masking the Column Values Returned to the Application
          1. Using the DECODE Function
        3. Implementing Row-Level Security with Views
      4. Using VPD to Implement Row-Level Security
      5. Summary
    12. 7. Caching
      1. Caching Data with Oracle and PHP
        1. Caching Queries on the Database Server
          1. Processing SQL Statements
          2. Using Bind Variables to Increase the Probability of Shared Pool Cache Hits
        2. Using Oracle's Application Contexts for Caching
          1. Creating a Global Application Context
          2. Manipulating Data Held in a Global Context
          3. Resetting Values in a Global Context
        3. Caching Mechanisms Available in PHP
          1. Choosing a Caching Strategy
          2. Caching Function Calls with the PEAR::Cache_Lite Package
          3. Updating Cached Data
      2. Implementing Notification-Based Caching
        1. Using Database Change Notification
          1. Auditing Notification Messages
          2. Building a PL/SQL Procedure Sending Notifications to the Web Server
          3. Performing Configuration Steps Required for Change Notification
          4. Building the Notification Handler
          5. Creating a Query Registration for the Notification Handler
          6. Quick Test
        2. Implementing Notification-Based Caching with PEAR::Cache_Lite
      3. Summary
    13. 8. XML-Enabled Applications
      1. Processing XML in PHP/Oracle Applications
        1. Processing XML Data with PHP
          1. Creating XML with the DOM PHP Extension
          2. Querying a DOM Document with XPath
          3. Transforming and Processing XML with XSLT
        2. Performing XML Processing inside the Database
          1. Using Oracle SQL/XML Generation Functions
          2. Moving All the XML Processing into the Database
          3. Storing XML Data in the Database
          4. Performing XSLT Transformations inside the Database
      2. Building PHP Applications on Oracle XML DB
        1. Using Oracle Database for Storing, Modifying, and Retrieving XML Data
          1. Database Storage Options for XML Data in Oracle Database
          2. Using XMLType for Handling XML Data in the Database
          3. Using XML Schemas
          4. Retrieving XML Data
        2. Accessing Relational Data Through XMLType Views
          1. Using XMLType Views
          2. Creating XML Schema-Based XMLType Views
          3. Performing DML Operations on XML Schema-Based XMLType Views
        3. Using Oracle XML DB Repository
          1. Manipulating Repository Resources with PL/SQL
          2. Accessing Repository Resources with SQL
          3. Taking Advantage of Standard Internet Protocols
        4. Handling Transactions
      3. Querying Data with Oracle XQuery
        1. Using XQuery to Construct XML from Relational Data
        2. Breaking up XML into Relational Data
      4. Summary
    14. 9. Web Services
      1. Exposing a PHP/Oracle Application as a Web Service Using PHP SOAP Extension
        1. Communicating Using SOAP
        2. What you Need to Build a SOAP Web Service
        3. Building a SOAP Web Service on Top of a PHP/Oracle Application
        4. Building the Business Logic of a Web Service Inside the Database
          1. Creating an XML Schema to Validate Incoming Documents
          2. Generating Unique IDs for Incoming Documents
          3. Creating PL/SQL Subprograms Implementing the Business Logic of the Web Service
        5. Building a PHP Handler Class
        6. Using WSDL
        7. Creating a SOAP Server with PHP's SOAP Extension
        8. Building a SOAP Client to Test the SOAP Server
      2. Adding Security
        1. Implementing Authorization Logic Inside the Database
        2. Creating a PHP Handler Class
        3. Creating a WSDL Document
        4. Creating a Client Script
      3. Summary
    15. 10. AJAX-Based Applications
      1. Building AJAX-Based PHP/Oracle Applications
        1. AJAX Interactions
        2. Designing an AJAX/PHP/Oracle Monitoring Application
        3. Building Blocks of an AJAX-Based Solution
          1. Creating the Data Structures
          2. Building the PHP Script that will Process AJAX Requests
          3. Using the XMLHttpRequest JavaScript Object
          4. Putting It All Together
          5. Using Caching to Further Improve Responsiveness
      2. Implementing Master/Detail Solutions with AJAX
        1. Planning a Master/Detail Solution that uses AJAX
        2. Building the Sample Application
          1. Creating the Data Structures
          2. Generating HTML with Oracle XQuery
          3. Sending Post Requests with AJAX
          4. Styling with CSS
          5. Putting It All Together
      3. Summary
    16. A. Installing PHP and Oracle Software
      1. Installing Oracle Database Software
        1. Installing Oracle Database Enterprise/Standard Editions
        2. Installing Oracle Database Express Edition (XE)
          1. Installing Oracle Database XE on Windows
          2. Installing Oracle Database XE on Linux
        3. Installing Apache HTTP Server
      2. Installing PHP
        1. Installing PHP on Windows
        2. Installing PHP on Unix-Like Systems
        3. Testing PHP
      3. Bridging the Gap Between Oracle and PHP
        1. Oracle Instant Client
        2. Enabling the OCI8 Extension in an Existing PHP Installation
        3. Installing SQL*Plus Instant Client
      4. Installing Zend Core for Oracle
        1. Installing Zend Core for Oracle on Windows
        2. Installing Zend Core for Oracle on Linux