问题描述
我在Amazon RDS上建立了一个Oracle数据库,并试图用PHP连接到它.
I have an Oracle database set up on Amazon RDS and am trying to connect to it in PHP.
我相当确定我的连接字符串正确,因为我使用sqlplus连接并且能够检索数据.该服务器是Amazon Linux服务器,但是我也尝试使用其他服务器进行连接并收到错误消息:
I am fairly sure my connection string is correct because I connected using sqlplus and am able to retrieve data. The server is an Amazon Linux server, however I have also tried to connect using a different server and get the error:
我是否需要在服务器或数据库服务器中进行其他设置?我刚刚开始使用AWS,并且不确定是否需要做其他任何事情.
Is there any more set up that I need to do in either the server or the database server, I have just started using AWS and am not sure if anything else needs to be done.
这是我的测试代码:
<html>
<head>
<title>PHP Test</title>
</head>
<body>
<?php
echo "OCI Test<br>";
$tns = "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=xyz.abc.us-west-2.rds.amazonaws.com)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=orcl)));";
echo "<pre>$tns</pre>\n";
$username = "xxx";
$password = "yyy";
$db = @oci_connect($username, $password, $tns);
if (!$conn)
{
$e = oci_error();
trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);
}
$sql = "select * from city";
$stmt = OCIParse($db, $sql);
if(OCIExecute($stmt))
{
while(OCIFetchInto($stmt, $row, OCI_RETURN_NULLS))
{
echo $row[0]. "-" . $row[1]."<br>";
}
}
OCIFreeStatement($stmt);
?>
</body>
</html>
而且Amazon Linux服务器什么也没显示,而我可以访问的另一台服务器却显示错误,是否为此进行了配置更改?
Also the Amazon Linux server just shows nothing, while another server that I have access to gives errors, is there a configuration change for this?
推荐答案
$tns
变量看起来不正确.
尝试
$tns = "(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=xyz.abc.us-west-2.rds.amazonaws.com)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=orcl)));";
这篇关于无法将我的RDS Oracle实例连接到PHP服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!