Database Articles

  Home arrow Database Articles arrow PHP`s Oracle Functionality
DATABASE ARTICLES

PHP`s Oracle Functionality
By: Apress Publishing
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2010-12-08

    Table of Contents:
  • PHP`s Oracle Functionality
  • Connecting to the Database

  •  
     

    SEARCH CODEWALKERS

    TOOLS YOU CAN USE

    advertisement

    PHP`s Oracle Functionality


    (Page 1 of 2 )

    How do you use Oracle Database XE's features within your PHP applications? This seven-part article series answers that question. It is excerpted from chapter 32 of the book Beginning PHP and Oracle: From Novice to Professional, written by W. Jason Gilmore and Bob Bryla (Apress; ISBN: 1590597702).

    Now that you have a good understanding of Oracle Database XEs architecture, column datatypes, basic SQL commands, and security methods, its time to leverage these database features within your PHP applications by using the Oracle OCI8 extension. In Chapter 24, we introduced PDO, a database-independent abstraction layer. In contrast, however, the Oracle OCI8 extension provides you with access to most, if not all, Oracle Database XE features with a high level of performance compared to other extensions. If your PHP applications will access Oracle databases exclusively, OCI8 is your best choice.

    In this chapter, you will learn how to perform database queries and DML (Data Manipulation Language) functions, such as table INSERT, DELETE, UPDATE, and SELECT, using PHP function calls. In addition, we show you how to extract database metadata using PHP functions and SELECT statements against database data dictionary views.

    Prerequisites

    The primary prerequisite for using OCI8 is to configure your installation of PHP to use it. As we showed you in Chapter 27 in the section on configuring Oracle and PHP, locate the PHP configuration file php.ini you created in Chapter 2 and locate this line in the file itself:

    ;extension=php_oci8.dll

    Remove the semicolon at the beginning of the line and save the file in its original location. Restart the Apache HTTP server on your workstation, and the OCI8 extensions are available to all of your PHP applications.


    Note  In PHP 5, the OCI8 extension function names are more standardized; for example, the PHP 4 version of OCILogin() is now oci_connect() in PHP 5. The old names still exist as aliases, but you are highly encouraged to use the new naming conventions in all of your applications.


    Using Database Connections

    Before you can do anything with the database, you must connect to it first and provide the required authentication information and database name. When you installed the database in Chapter 27, you ran the script in Listing 32-1 to test connectivity with the database. 

    Listing 32-1. PHP Code to Test Oracle Connectivity

    <?php
    if ($conn = oci_connect('system', 'yourpassword', '//localhost/xe')) {
        print 'Successfully connected to Oracle Database XE!';
        oci_close($conn);
    }
    else {
        $errmsg = oci_error();
        print 'Oracle connect error: ' . $errmsg['message'];
    }
    ?>

    The call to oci_connect() establishes the connection to the database. In all future database requests, you use the variable $conn to reference the established connection. You also have three different options for specifying the target database in your connection request; well cover these options after reviewing the connection types. Finally, you'll most likely want to know how to close a connection, so we'll tell you how, as well as what happens behind the scenes.

    More Database Articles Articles
    More By Apress Publishing

    blog comments powered by Disqus

    DATABASE ARTICLES ARTICLES

    - Completing a Book Inventory Management System
    - Uploading Images for a Book Inventory Manage...
    - Finishing the Add Book Story for a Book Inve...
    - Integration Testing for a Book Inventory Man...
    - User Stories for a Book Inventory Management...
    - Unit Testing a Book Inventory Management Sys...
    - Testing a Book Inventory Management System
    - Implementing Models for a Book Inventory Man...
    - Book Inventory Application: Publishers and B...
    - Handling Publishers in a Book Inventory Mana...
    - Publisher Administration for Book Inventory ...
    - Book Inventory Management
    - Using the SQL Reference Manual
    - Using Oracle SQL Developer with SQL Statemen...
    - Fixing Errors with Oracle SQL Developer


    © 2003-2012 by Developer Shed. All rights reserved. DS Cluster 2 - Follow our Sitemap