Reputation: 33
On a MySQL database, I'm using the following PHP code to successfully retrieve rows and place the contents of two columns into a table:
while ($row = mysqli_fetch_array($query))
{
echo '<tr>
<td>'.$row['sc_service'].'</td>
<td>'.$row['sc_color'].'</td>
</tr>';
}
Now, I'm trying to take this code and use it against an Oracle database. I've tried swapping in what appears to be the OCI counterpart...
while (($row = oci_fetch_array($stid1, OCI_BOTH))!= false)
{
echo '<tr>
<td>'.$row['sc_service'].'</td>
<td>'.$row['sc_color'].'</td>
</tr>';
}
...but the column variables (sc_service
and sc_color
) are not being defined.
Question: Is there a different approach required to define the column variable? I'd like to use the variables in other areas of the PHP code, and not just to populate a table.
I'm able to execute the following PHP script successfully using OCI functions (a properly populated table is returned), so I know I'm connecting to the database successfully:
<?php include 'database.php'; ?> // my Oracle database oci_connect call
<?php
$stid = oci_parse($connect, 'SELECT * FROM service_color');
if (!$stid) {
$e = oci_error($connect);
trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);
}
$r = oci_execute($stid);
if (!$r) {
$e = oci_error($stid);
trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);
}
print "<table border='1'>\n";
while ($row = oci_fetch_array($stid, OCI_ASSOC+OCI_RETURN_NULLS)) {
print "<tr>\n";
foreach ($row as $item) {
print " <td>" . ($item !== null ? htmlentities($item, ENT_QUOTES) : " ") . "</td>\n";
}
print "</tr>\n";
}
print "</table>\n";
oci_free_statement($stid);
oci_close($connect);
Upvotes: 1
Views: 387
Reputation: 13024
Field names in Oracle are typically always uppercase, and array keys in PHP are case-sensitive:
while (($row = oci_fetch_array($stid1, OCI_BOTH))!= false)
{
echo '<tr>
<td>'.$row['SC_SERVICE'].'</td>
<td>'.$row['SC_COLOR'].'</td>
</tr>';
}
Upvotes: 1