DISPLAYING ORACLE DATA WITH PHP
Once a connection to Oracle has been established in your PHP script, the following code demonstrates how to display data pulled from the Oracle database.
Sample PHP Code:
<?php
// A connection to oracle has been made using the $conn variable
// Assign SQL
$sql = "select * from TEST_TABLE order by name";
// Parse SQL
$stmt = OCIParse($conn,$sql);
// Bind Oracle columns to php variables
OCIDefineByName($stmt,"ID",$id);
OCIDefineByName($stmt,"NAME",$name);
OCIDefineByName($stmt,"EMAIL",$email);
OCIDefineByName($stmt,"PHONE",$phone);
// Oracle converts all column names into UPPERCASE
// Run SQL
OCIExecute($stmt);
// Begin table in HTML
?>
<table width="450" cellpadding="0" cellspacing="0" border="0">
<tr>
<td bgcolor="#CCCCCC">ID</td>
<td bgcolor="#CCCCCC">Name</td>
<td bgcolor="#CCCCCC">Email</td>
<td bgcolor="#CCCCCC">Phone</td>
</tr>
<?php
// Loops through each row of data and outputs it into an HTML table row
while (OCIFetch($stmt)){
?>
<tr>
<td><?php echo $id; ?></td>
<td><?php echo $name; ?></td>
<td><?php echo $email; ?></td>
<td><?php echo $phone; ?></td>
</tr>
<?php
}
?>