September 21, 2018
Hot Topics:

Combining an Oracle Database with PHP to Manage Data

  • October 5, 2007
  • By Deepak Vohra
  • Send Email »
  • More Articles »

Listing 2: retrieveOracleData.php



  (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))

$connection = oci_connect($username, $password, $db);
$stmt = oci_parse($connection, "SELECT * from OE.CATALOG
   WHERE JOURNAL=:journal");

$journal='Oracle Magazine';
oci_bind_by_name($stmt, ":journal", $journal);

$r = oci_execute($stmt);

$nrows = oci_fetch_all($stmt, $results);

echo "<table border><tr><th>Catalog


for ($i = 0; $i < $nrows; $i++) {
   echo "<tr>\n";
   foreach ($results as $data) {
      echo "<td>$data[$i]</td>\n";
   echo "</tr>\n";

echo "</table>";



Next, run the retrieveOracleData.php script in the Apache web server with the URL http://localhost/retrieveOracleData.php. The Oracle database data gets retrieved and displayed in an HTML table, as shown in Figure 2.

Click here for a larger image.

Oracle2.jpg Data gets retrieved and displayed in an HTML table.


PHP provides the OCI8 extension to connect to an Oracle database and runs SQL queries in the database. In this article, you installed the OCI8 extension, established a connection to Oracle database, created a database table, and retrieved database table data.

About the Author

Deepak Vohra (dvohra09@yahoo.com) is a Sun Certified Java Programmer and a Sun Certified Web Component Developer, and has published in devx, FTPOnline, JavaBoutique, ONJava, and java.net.

Page 5 of 5

Comment and Contribute


(Maximum characters: 1200). You have characters left.



Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

By submitting your information, you agree that developer.com may send you developer offers via email, phone and text message, as well as email offers about other products and services that developer believes may be of interest to you. developer will process your information in accordance with the Quinstreet Privacy Policy.


Thanks for your registration, follow us on our social networks to keep up-to-date