Home arrow Apache arrow Page 2 - Working With Oracle on Windows: Part 1

Working With Oracle on Windows: Part 1

You know PHP and MySQL, but wouldn't it be nice to know Oracle? Well, Ben's come to the rescue with his article series on using Oracle with PHP on Windows...

Author Info:
By: Ben Shepherd
Rating: 2 stars2 stars2 stars2 stars2 stars / 3
March 02, 2003
  1. · Working With Oracle on Windows: Part 1
  2. · Configuring Apache and PHP
  3. · Conclusion

print this article

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.php respectively 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.

LoadModule php4_module d:/php/sapi/php4apache.dll
AddType application/x-httpd-php .php

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:

  <? phpinfo(); ?>

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:

CREATE SEQUENCE your_sequence_name;
CREATE TRIGGER your_trigger_name
ON your_table_name
SELECT  your_sequence_name.nextval
INTO  :new.pk_column
FROM  dual;

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:

//This function will connect us to the database
function connectObject()
 global $database_connection;
$database_connection = ocilogon("scott", "tiger", "yadayada.domain.com");

// This function will handle the SQL statements returning the number of rows selected.
function sqlHandler($sql_query, &$recordset)
 global $database_connection;
 if (!$database_connection)
    $parsed = ociparse($database_connection, $sql_query);
 if (func_num_args() == 2)
  $number_of_rows = ocifetchstatement($parser, $recordset);
  // For the fun of it lets get the number of records
        $number_of_rows = ocirowcount($parsed);
// Lets get everything from your table 
$sql_statement = "SELECT * FROM your_table";
$number_of_records = sqlHandler($sql_statement, $records);

echo "There is $records records in your table.\n"

The ORA library is very similar in language using functions like Ora_Open(), Ora_Parse(), Ora_Exec(), Ora_close(), Ora_Logoff().

blog comments powered by Disqus

- Programmatically Manipulating Microsoft Exce...
- Installing PHP under Windows
- Compressing Web Content with mod_gzip and mo...
- Compressing Web Output Using mod_deflate and...
- Setting Up Apache 2.0.45 to Parse PHP Pages
- Custom Error 404 Documents with PHP
- Using Apache and PHP on Mac OS X
- ASP: Active Sessions, Active Logins and Tota...
- Working With Oracle on Windows: Part 1
- The Quick-n-Dirty Guide to Setting Up Apache...
- Installing Apache With SSL: The Complete Gui...
- 7 Powerful .htaccess Customization Tips
- Trap And Get Notified: A Practical Solution ...
- One Way To Use Server Side Includes
- Using ForceType For Nicer Page URLs

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 

Developer Shed Affiliates


© 2003-2019 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials