在MySQL数据库中,我使用以下PHP代码成功检索行并将两列的内容放入表中:
while ($row = mysqli_fetch_array($query))
{
echo '<tr>
<td>'.$row['sc_service'].'</td>
<td>'.$row['sc_color'].'</td>
</tr>';
}
现在,我尝试使用此代码并将其用于Oracle数据库。我已经尝试过交换似乎是OCI的对手......
while (($row = oci_fetch_array($stid1, OCI_BOTH))!= false)
{
echo '<tr>
<td>'.$row['sc_service'].'</td>
<td>'.$row['sc_color'].'</td>
</tr>';
}
...但未定义列变量(sc_service
和sc_color
)。
问题:是否需要使用不同的方法来定义列变量?我想在PHP代码的其他区域使用变量,而不仅仅是填充表格。
我能够使用OCI功能成功执行以下PHP脚本(返回正确填充的表),因此我知道我已成功连接到数据库:
<?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);
答案 0 :(得分:1)
Oracle中的字段名称通常总是大写的,PHP中的数组键区分大小写:
while (($row = oci_fetch_array($stid1, OCI_BOTH))!= false)
{
echo '<tr>
<td>'.$row['SC_SERVICE'].'</td>
<td>'.$row['SC_COLOR'].'</td>
</tr>';
}