There are two kinds of database-driven applications. Ones that use databases just to store data, performing all the operations on it on the client side; and the others that use databases 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 application inside the database is always a good idea, you should bear in mind that not all the databases available today allow you to put this into practice. However, the Oracle database offers record‑breaking performance, scalability, and reliability. The partnership formed by Oracle and PHP, an open-source scripting language, is an excellent solution for building high-performance, scalable, and reliable data-driven web applications.
This chapter contains technical information that will help you to quickly start developing PHP applications on top of Oracle. It begins with a concise discussion of why you might want to use PHP in conjunction with Oracle, followed by the PHP and Oracle alternatives. Having learned what advantages the PHP/Oracle combination has over its competitors, you might want to see its strengths in action. If you don't have PHP and Oracle database software installed, you can read the What You Need to Start section in this chapter. This section discusses the pieces of software required to run the examples provided in this book. You could also read Appendix A Installing PHP and Oracle Software, which provides a quick-and-dirty guide to installing and configuring these software components to work together in your system.
Once you have all the required pieces of software installed, configured, and working properly, you are ready to build your first PHP/Oracle application. For the sake of simplicity, the sample application provided in this chapter simply obtains the current time from the database and then displays it to the user. In spite of its simplicity, the example demonstrates how to perform two basic things that every PHP/Oracle application must take care of. Specifically, it demonstrates how a PHP application can connect to an Oracle database and then interact with it.
If you have already got your feet wet with PHP/Oracle development, you probably will not be interested in reading this quick-start chapter. If so, you can move to Chapter 2, which discusses how to use PHP's OCI8 extension, providing a common way to interact with Oracle database from PHP.
With Oracle as the back-end database, you can develop and deploy data-driven PHP applications with a powerful, proven, and industry-leading infrastructure, while still taking advantage of PHP's ease of use, short development time, and high performance.
One of the key reasons behind PHP's popularity is its simplicity. So, you don't have to be a PHP guru to start building PHP applications on Oracle. All you need to learn are a few APIs, which allow you to interact with the database and handle the received data. The example discussed later in this chapter will show you how to build a simple PHP/Oracle application by using a few OCI8 functions.
PHP's Object-Oriented features, available since PHP 3 and significantly improved in PHP 5, help you create complex applications easily and quickly. Once a class has been written and debugged, you can reuse it in a number of ways. This allows you to reuse well‑designed pieces of object-oriented code over and over, reducing or eliminating redundant code in your applications. For a detailed discussion of how to combine the power of object-oriented PHP and Oracle, refer to Chapter 5
From a PHP developer's perspective, developing PHP/Oracle applications is much easier than developing, PHP/MySQL applications. This is because, in the case of Oracle database, you may implement key business logic of the application on the database side. This not only reduces the amount of PHP code, but also improves the performance and scalability of the entire application.
If you are a PHP developer who tends to think that Oracle database represents a complicated, hard-to-drive mechanism, you should realize that—no matter how complex the Oracle insides may be—what really matters is that Oracle offers a lot of comprehensive tools intended to help you manage database objects and access data stored in the database with minimum effort. Although coverage of all the tools is beyond the scope of this book, the examples provided throughout the book will help you to obtain a good understanding of how Oracle SQL and PL/SQL—two of the most popular Oracle tools—are used to access and manipulate data, metadata, and other database resources.
Although you can process your application data on the client side in the case of Oracle database, there are many advantages of processing data inside the database. From a performance standpoint, moving processing to the data allows you to:
Reduce the communication overhead between the web server and the database
Conserve the web server resources
Take advantage of optimizations and indexing techniques provided by the Oracle database
By using triggers and stored procedures, you can develop an application whose business logic resides entirely inside the database. Moving data processing to the database tier is particularly useful if your application is database intensive. This is because your application doesn't need to transfer a large amount of data between tiers while processing data inside the database; instead, it sends only the final product across the wire.
Oracle gets high marks when it comes to 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. By using both of these technologies in a complementary way, you will be able to:
Move key business logic of your application to the data
Protect your application against data loss
Take advantage of Oracle security technologies
Leverage the power of object-oriented technology
Build transactional applications
Develop robust XML-enabled applications
All these capabilities make using PHP in conjunction with Oracle a natural choice when it comes to developing mission-critical, highly secure data-driven web applications.
With Oracle as the back-end database, you can develop and deploy data-driven PHP applications with a powerful, proven, and industry-leading infrastructure, while still taking advantage of PHP's ease of use, short development time, and high performance.
One of the key reasons behind PHP's popularity is its simplicity. So, you don't have to be a PHP guru to start building PHP applications on Oracle. All you need to learn are a few APIs, which allow you to interact with the database and handle the received data. The example discussed later in this chapter will show you how to build a simple PHP/Oracle application by using a few OCI8 functions.
PHP's Object-Oriented features, available since PHP 3 and significantly improved in PHP 5, help you create complex applications easily and quickly. Once a class has been written and debugged, you can reuse it in a number of ways. This allows you to reuse well‑designed pieces of object-oriented code over and over, reducing or eliminating redundant code in your applications. For a detailed discussion of how to combine the power of object-oriented PHP and Oracle, refer to Chapter 5
From a PHP developer's perspective, developing PHP/Oracle applications is much easier than developing, PHP/MySQL applications. This is because, in the case of Oracle database, you may implement key business logic of the application on the database side. This not only reduces the amount of PHP code, but also improves the performance and scalability of the entire application.
If you are a PHP developer who tends to think that Oracle database represents a complicated, hard-to-drive mechanism, you should realize that—no matter how complex the Oracle insides may be—what really matters is that Oracle offers a lot of comprehensive tools intended to help you manage database objects and access data stored in the database with minimum effort. Although coverage of all the tools is beyond the scope of this book, the examples provided throughout the book will help you to obtain a good understanding of how Oracle SQL and PL/SQL—two of the most popular Oracle tools—are used to access and manipulate data, metadata, and other database resources.
Although you can process your application data on the client side in the case of Oracle database, there are many advantages of processing data inside the database. From a performance standpoint, moving processing to the data allows you to:
Reduce the communication overhead between the web server and the database
Conserve the web server resources
Take advantage of optimizations and indexing techniques provided by the Oracle database
By using triggers and stored procedures, you can develop an application whose business logic resides entirely inside the database. Moving data processing to the database tier is particularly useful if your application is database intensive. This is because your application doesn't need to transfer a large amount of data between tiers while processing data inside the database; instead, it sends only the final product across the wire.
Oracle gets high marks when it comes to 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. By using both of these technologies in a complementary way, you will be able to:
Move key business logic of your application to the data
Protect your application against data loss
Take advantage of Oracle security technologies
Leverage the power of object-oriented technology
Build transactional applications
Develop robust XML-enabled applications
All these capabilities make using PHP in conjunction with Oracle a natural choice when it comes to developing mission-critical, highly secure data-driven web applications.
Now that you have a rough idea of what the PHP/Oracle combination has to offer, it is worth taking a moment to familiarize yourself with some other popular combinations that can be used as alternatives to PHP and Oracle. Exploring such alternatives, including their advantages and disadvantages, can help you understand better whether PHP and Oracle best suit your needs or there is another combination that suits your needs better.
Although PHP supports all the major relational databases, including commercial ones such as IBM's DB2 and Microsoft SQL Server, MySQL, an open-source database, is still a popular choice among PHP developers. The major reason behind MySQL's popularity is that it is completely free under the GPL license.
Of those based on Oracle, JSF and Oracle is probably one of the most powerful combinations available. To make JSF/Oracle application development easier, Oracle offers ADF Faces, a fully compliant JSF component library including over 100 JSF components.
MySQL is extremely popular among the open‑source community that uses PHP. There are several reasons behind MySQL's popularity among PHP developers. The most significant ones are as follows:
Completely free under the GPL license
Low Total Cost of Ownership (TOC)
PHP natively supports MySQL—no additional modules are required
All these factors make MySQL a natural choice for web hosts providing support for PHP. However, you should realize that the PHP/MySQL combination is a good solution for small data-driven web applications whereas professional-quality applications require much more.
JavaServer Faces technology is a new server-side user interface (UI) component framework that is quickly becoming the standard web-application framework for J2EE applications. The biggest advantage of JavaServer Faces technology is that it enables web developers to apply the Model-View-Controller (MVC) principle, thus achieving a clean separation between the model and presentation layers of a web application. The entire user interaction with the application is handled by a front-end Faces servlet.
The only disadvantage the JSF and Oracle combination has compared to PHP and Oracle is that JavaServer Faces is a bit more difficult to learn than PHP.