Combining an Oracle Database with PHP to Manage Data
Listing 2: retrieveOracleData.php
<?php
$username='OE';
$password='pw';
$db='(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = ORCL)
)
)';
$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);
if($nrows>0){
echo "<table border><tr><th>Catalog
Id</th><th>Journal</th><th>Publisher</th><th>Edition</th>
<th>Title</th><th>Author</th></tr>";
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.
Conclusion
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.



Solid state disks (SSDs) made a splash in consumer technology, and now the technology has its eyes on the enterprise storage market. Download this eBook to see what SSDs can do for your infrastructure and review the pros and cons of this potentially game-changing storage technology.