使用PHP从Oracle数据库中检索数据

时间:2013-10-11 14:50:49

标签: php oracle10g

我在从远程服务器上的Oracle 10g数据库中检索数据时遇到问题。我在Linux Debian Web服务器上使用PHP,oci8已启用并正常工作。我只得到一个空白页面。代码如下:

<?php
$conn = oci_connect('username','password','//server IP address:1521/servicename');

if (!$conn) {
    $e = oci_error();
    trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);
}
// Prepare the statement
$stid = oci_parse($conn, 'SELECT * FROM table');
if (!$stid) {
    $e = oci_error($conn);
    //trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);
}
// Perform the logic of the query
$r = oci_execute($stid);
if (!$r) {
    $e = oci_error($stid);
    trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);
}
// Fetch the results of the query
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) : "&nbsp;") . "</td>\n";
    }
    print "</tr>\n";
}
print "</table>\n";
oci_free_statement($stid);
oci_close($conn);
?>

我不确定如何清楚地定义我想连接的数据库,因为服务器上有几个Oracle数据库。

非常感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

问题现在已经解决。

一旦我添加了错误报告,我就得到了一个ocienvnlscreate()失败的LD_LIBRARY_PATH问题。这取决于为LD_LIBRARY_PATH设置的路径或instantclient目录的权限,它是后者。非常感谢您对Maximus2012的回复。

相关问题