October 23, 2014
Hot Topics:
RSS RSS feed Download our iPhone app

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.



Sitemap | Contact Us

Rocket Fuel