Cannot connect my RDS Oracle instance to a PHP server

蓝咒 提交于 2019-12-12 01:57:02

问题


I have an Oracle database set up on Amazon RDS and am trying to connect to it in PHP.

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:

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.

ORA-12154: TNS:could not resolve the connect identifier specified... Line 19.

Here is my test code:

<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>

Edit: 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?


回答1:


The $tns variable looks wrong.

Try

$tns = "(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=xyz.abc.us-west-2.rds.amazonaws.com)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=orcl)));";


来源:https://stackoverflow.com/questions/35933251/cannot-connect-my-rds-oracle-instance-to-a-php-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!