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 远程桌面文档内容复制粘贴,格式会变化
  • ¥15 关于#java#的问题:找一份能快速看完mooc视频的代码
  • ¥15 这种微信登录授权 谁可以做啊
  • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码
  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”
  • ¥15 网络设备配置与管理这个该怎么弄
  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题