Working With Oracle on Windows: Part 1 - Configuring Apache and PHP(Page 2 of 3 )

Unless you've been on vacation for the last few years, you have definitely heard of open source products Apache Web Server and PHP. You must download and configure Apache on your system from http://nagoya.apache.org/mirror/httpd/binaries/win32/and www.php.net/download.phprespectively for the latest releases. These two products are free and will enable you to use Oracle effectively. The pages should look something like this.

Apache Download Page

PHP Download Page

Run the setup utility and install the Oracle client software. This is done by connecting to a database with SQLPlus and attempting to login in using the user name "scott" and the password "tiger".

Ok, now this is going well. We have Oracle working and connecting us to a database. But as stated above, we must configure both PHP and Apache so that they are able communicate with the new Oracle database. What we have at the moment is a php and Apache zip files. So, you simply use WinZip to extract the zip files and install following all the instructions.

Configuration Process

Make sure when you are asked for a server type that you select Apache and set the extensions to .php. The php files should be in the C:\PHP directory. Now copy the php dynamic link library file say, php4ts.dll, into your system32 directory. This is done simply by typing copy C:\php\php4ts.dll to c:\winnt\system32 in DOS prompt.

Letís configure PHP and Apache so the Apache server can communicate with PHP and Oracle. In the c:\winnt\php.ini file make sure, this is important, that you remove the; in front of extension=php_oci8.dll line. This will allow us to use the OCI library which we will use in this article to give you the best information on offer. Also, be sure that the extension directory is the same as the extensions file which is located in the PHP folder. The line extension_dir = "C:\PHP\extensions" will be correct.

PHP should now be ready to use. But PHP is still foreign to Apache. So we must alter the http daemon configuration file (i.e. the httpd.conf file) to add the php file type. The following code should be entered inside this file, preferably at the base.

You must test that all is working in synch. So by creating a php file say, C:/Program Files/Apache Group/Apache/htdocs/mysite/phpinfo.php, type the following code:

<html> <body> <? phpinfo(); ?> </body></html>Open a browser and type in the URL http://localhost/mysite/phpinfo.php. The page should read that Oracle is enabled.

Phew, now that we are up and running let's do something productive. Let's create a simple dynamic webpage. Firstly, we'll logon to SQLPlus. Creating a table is simple, so let's assume that we have created a table names your_table_name. Let's create a sequence that will increment an id column - which in turn is the primary key - each time a row is inserted into the table. Create a sql file, say table.sql and type the following:

To make this sequence operable, run the script in SQLPlus by typing @table. To access this database, PHP has 2 libraries that work with Oracle - The Oracle Library (ORA) and The Oracle Client Interface Library (OCI). The question is which one do we use. The answer is, if the system supports it, use the OCI library. OCI is superior to that of the ORA in performance. Notice that we supported the OCI library

To use this database we must create a php file, say yadayada.php, and type in the following code using the OCI library: