Apache
  Home arrow Apache arrow Page 2 - Working With Oracle on Windows: Part 1
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Dedicated Servers  
Actuate Whitepapers 
Moblin 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
APACHE

Working With Oracle on Windows: Part 1
By: Ben Shepherd
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 2 stars2 stars2 stars2 stars2 stars / 3
    2003-03-02

    Table of Contents:
  • Working With Oracle on Windows: Part 1
  • Configuring Apache and PHP
  • Conclusion

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    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:

    <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:

    CREATE SEQUENCE your_sequence_name;
    CREATE TRIGGER your_trigger_name
    BEFORE INSERT
    ON your_table_name
    FOR EACH ROW
    BEGIN
    SELECT  your_sequence_name.nextval
    INTO  :new.pk_column
    FROM  dual;
    END;

    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)
     {
      connectObject();
        }
        $parsed = ociparse($database_connection, $sql_query);
        ociexecute($parser);
     if (func_num_args() == 2)
     {
      $number_of_rows = ocifetchstatement($parser, $recordset);
        }
        else
     {
      // For the fun of it lets get the number of records
            $number_of_rows = ocirowcount($parsed);
        }
     return($nrows);
     }
    // 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().

    More Apache Articles
    More By Ben Shepherd


     

    APACHE ARTICLES

    - 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







    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway