CHAITANYA PHP AND ORACLE - Peoplepeople.cs.ksu.edu/~hankley/d764/tut06/CHAITANYA_PHP+ORA.pdf · CIS...

10
AN APPLICATION IN PHP WITH ORACLE DATABASE AS BACKEND AND DEPLOYED ON APACHE WEBSERVER CHAITANYA R MITTAPELLI [email protected] CIS 764, CIS, KSU Fall 2006 Purpose: To develop a small application in PHP with connection to a oracle database. Overview: Here we develop a small application called as Library Information System. It connects to the oracle database to retrieve the information about the books. Prerequisites; Before starting the tutorial, you should: 1. Have access to or have installed Oracle Database 10g (Release 2 or Release 1). One can download it from Oracle Technology Network (http://www.oracle.com/technology/software/products/database/oracle10g/index.html ). 2. PHP 4.3.4 or later. http://www.php.net/downloads.php 3. A web server such as Apache 1.3 or later. http://httpd.apache.org/download.cgi

Transcript of CHAITANYA PHP AND ORACLE - Peoplepeople.cs.ksu.edu/~hankley/d764/tut06/CHAITANYA_PHP+ORA.pdf · CIS...

AN APPLICATION IN PHP WITH ORACLE DATABASE

AS BACKEND AND DEPLOYED ON APACHE WEBSERVER CHAITANYA R MITTAPELLI [email protected] CIS 764, CIS, KSU Fall 2006

Purpose:

To develop a small application in PHP with connection to a oracle database.

Overview:

Here we develop a small application called as Library Information System.

It connects to the oracle database to retrieve the information about the books.

Prerequisites;

Before starting the tutorial, you should:

1. Have access to or have installed Oracle Database 10g (Release 2 or Release 1). One

can download it from Oracle Technology Network

(http://www.oracle.com/technology/software/products/database/oracle10g/index.html).

2. PHP 4.3.4 or later.

http://www.php.net/downloads.php

3. A web server such as Apache 1.3 or later.

http://httpd.apache.org/download.cgi

The following steps have to be performed: 1.Creating the tables. The following tables have to be created. Table Book with columns BOOKID,TITLE,AUTHOR,TOTALCOPIES,AVAILABLE. BOOKID is the primary key. 2. Writing the PHP code. A connection has to be established to the database. This is done with below given code. if ($c=OCILogon("chaitu", "cis764", "oracle.cis.ksu.edu")) echo "Successfully connected to Oracle.\n"; else { $err = OCIError(); echo "Oracle Connect Error " . $err[text]; }

Now we need to execute a select query from the PHP source Code. It is done by the following code. $s = OCIParse($c, "SELECT * FROM Book where TITLE='".$name."'"); OCIExecute($s, OCI_DEFAULT);

Now we need print the retrived rows with required formatting.It can be done with while (OCIFetch($s)) { echo "<tr><td align=center>"; echo ociresult($s, "TITLE") .; echo "</td><td align=center>"; echo ociresult($s, "AUTHOR") .; echo "</td><td align=center>"; echo ociresult($s, "TOTALCOPIES") .; echo "</td><td align=center>"; echo ociresult($s, "AVAILABLE") .;

In this way we build the required application. This Library Information System helps in searching the books. The home page looks as shown below.

Now we can search for a book either by book title or by author. Let’s select by book title. The page opens up and lets search for SOFTWARE ENGINERING

Click submit and then we see the following page

We can also search by Author as Shown below

The search results are displayed as shown below.

Thus we have successfully connected to the Oracle database from the PHP code and we have retrieved the required rows