doulingna9420 2017-01-18 20:20
浏览 71

页面不显示apache和php以及OCI8和Oracle Express 11g

I have Oracle Express 11g installed on Slackware linux and running. I am able to connect to it and run queries. I have apache and php installed and oci8 installed. phpinfo() is showing oci8 loaded and enabled. For the following simple php script the web page displays:

<?php echo "Hello World!!!"; ?>

So php in apache is working. Now for the following simple connect to oracle and show the version:

<html>
<body>
Oracle Version <br/>
<?php

$conn = oci_connect('SYSTEM', 'password', 'localhost/XE');

$stid = oci_parse($conn, 'select banner from v$version');
oci_execute($stid);

echo "<table>
";
while (($row = oci_fetch_array($stid, OCI_ASSOC+OCI_RETURN_NULLS)) != false) {
    echo "<tr>
";
    foreach ($row as $item) {
        echo "  <td>".($item !== null ? htmlentities($item, ENT_QUOTES) : "&nbsp;")."</td>
";
    }
    echo "</tr>
";
}
echo "</table>
";

?>
</body>
</html>

This is showing the following from view source in web browser:

<html>
<body>
Oracle Version <br/>
<table>
</table>
</body>
</html>

However when I run the script with /usr/bin/php oratest.php it outputs the following correctly:

<html>
<body>
Oracle Version <br/>
<table>
<tr>
  <td>Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production</td>
</tr>
<tr>
  <td>PL/SQL Release 11.2.0.2.0 - Production</td>
</tr>
<tr>
  <td>CORE      11.2.0.2.0      Production</td>
</tr>
<tr>
  <td>TNS for Linux: Version 11.2.0.2.0 - Production</td>
</tr>
<tr>
  <td>NLSRTL Version 11.2.0.2.0 - Production</td>
</tr>
</table>
</body>
</html>

How is this possible. Why would command line php work and apache serving up the same php script doesnt work. And phpinfo() served up by same apache is showing oci8 installed and enabled.

Please help if you have any ideas thanks in advance.

  • 写回答

1条回答 默认 最新

  • dongliao3450 2017-01-18 21:07
    关注

    The errors were occurring due to the ORACLE_HOME and LD_LIBRARY_PATH not being set correctly for the oracle instant client and oracle express 11g etc installation paths. I used putenv() php directive at start of php code and it worked with no errors.

    putenv("ORACLE_HOME=/u01/app/oracle/product/11.2.0/xe");
    putenv("LD_LIBRARY_PATH=/u01/app/oracle/product/11.2.0/xe/lib:/usr/lib64/oracle/12.1/client64/lib");
    
    评论

报告相同问题?

悬赏问题

  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序