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 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)