douyousu9691 2018-01-30 02:54
浏览 72
已采纳

需要帮助将mysqli_fetch_array引用转换为相应的OCI引用

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'>
";
while ($row = oci_fetch_array($stid, OCI_ASSOC+OCI_RETURN_NULLS)) {
  print "<tr>
";
  foreach ($row as $item) {
    print "    <td>" . ($item !== null ? htmlentities($item, ENT_QUOTES) : "&nbsp;") . "</td>
";
  }
  print "</tr>
";
}
print "</table>
";

oci_free_statement($stid);
oci_close($connect);
  • 写回答

1条回答 默认 最新

  • doudiejian5827 2018-01-30 10:44
    关注

    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>';
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作