Book Image

PHP Oracle Web Development: Data processing, Security, Caching, XML, Web Services, and Ajax

By : Yuli Vasiliev
Book Image

PHP Oracle Web Development: Data processing, Security, Caching, XML, Web Services, and Ajax

By: Yuli Vasiliev

Overview of this book

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.
Table of Contents (16 chapters)
PHP Oracle Web Development
Credits
About the Author
About the Reviewer
Preface

Bridging the Gap Between Oracle and PHP


By now you should have an Oracle database and Apache/PHP web server installed and working. However, before you can start developing PHP/Oracle applications, you have to enable the OCI8 extension in your PHP installation.

Oracle Instant Client

If you have both the database and web server installed on the same computer then you already have all the required Oracle components—no Instant Client is required, and so you can skip to the next section Enabling the OCI8 Extension in an Existing PHP Installation.

However, if you have the database and web server installed on different computers, you will need to install another piece of software, which will bridge the gap between Oracle and PHP. Specifically, you have to install the Oracle client libraries needed by the PHP OCI8 extension.

Consider Oracle Instant Client, a package containing Oracle client libraries required to run OCI, OCCI, and JDBC-OCI applications. Note that Oracle Instant Client comes with a free license for both development and production environments.

You can download a copy of Oracle Instant Client specific to your platform from the Instant Client web page on OTN at:

http://www.oracle.com/technology/tech/oci/instantclient/instantclient.html

From the above page, you should download the Basic Instant Client Package that includes all the files required to run OCI, OCCI, and JDBC-OCI applications.

On Windows, perform the following steps to install the Instant Client Package:

  • Download a copy of Oracle Instant Client from OTN.

  • Unzip the package into a single directory in your file system.

  • Add the path to the directory in which you unzipped the libraries to the PATH environment variable.

On UNIX-like platforms, perform the following steps:

  • Download a copy of Oracle Instant Client from OTN.

  • Unzip the package into a single directory in your file system.

  • Set LD_LIBRARY_PATH to the directory in which you unzipped the libraries.

Once you perform the above steps, you can move on and enable the OCI8 extension in your PHP installation.

Enabling the OCI8 Extension in an Existing PHP Installation

On Windows, perform the following steps to enable the OCI8 extension in your existing PHP installation:

  • In php.ini, uncomment the OCI8 extension line:

extension=php_oci8.dll
  • In php.ini, set the extension_dir directive to the directory in which php_oci8.dll resides:

extension_dir= c:\php\ext
  • Restart Apache.

On UNIX-like platforms, perform the following installation steps:

  • Run configure with Apache2 and OCI8 support:

# cd php-5xx
# ./configure --with-apxs2=/usr/local/apache2/bin/apxs \
--with-config-file-path=$HOME/apache/conf \
--with-oci8-instant-client=/home/instantclient10_2 \
--enable-sigchild
  • Rebuild PHP:

# make
# make install
  • Restart Apache:

/usr/local/apache2/bin/apachectl start

To make sure that the OCI8 extension was successfully enabled, you might run the testphp.php script discussed in the Testing PHP section earlier in this appendix. This time the output should include the OCI8 section verifying that OCI8 support is enabled.

Installing SQL*Plus Instant Client

Most of the examples in this book assume that you will use SQL*Plus when it comes to performing database administration or creating database objects. Note that SQL*Plus is installed by default when you install the Oracle Database software. So, if you are going to use a local database, you don't need to install SQL*Plus since you already have it. Otherwise, you might take advantage of SQL*Plus Instant Client—the SQL*Plus command-line tool that allows you to communicate with a remote database.

To install SQL*Plus Instant Client on your computer, perform the following steps:

  • Download the SQL*Plus Instant Client Package specific to your platform from the Instant Client web page on OTN at:

http://www.oracle.com/technology/tech/oci/instantclient/ instantclient.html

  • Unzip the package to the same directory where you unzipped the Basic Instant Client Package files.

  • Optionally, set a user environment variable NLS_LANG to an appropriate value.

Note

The NLS_LANG parameter is composed of three optional components: language, territory, and character set. To specify it, you use the following syntax: NLS_LANG = language_territory.charset. NLS_LANG defaults to AMERICAN_AMERICA.US7ASCII. For information about supported NLS_LANG settings, see Oracle documentation: Oracle Database Globalization Support Guide.

That is it. Now you can use SQL*Plus Instant Client to connect to a remote database.