PHP 在除一台服务器之外的所有服务器上的文件中途停止加载


PHP stops loading mid-way through a file on all but one server

我已经缩小了上一个问题的范围,发现问题出在PHP代码上。在 AWS 服务器和我的本地计算机上,页面无法完全呈现(即使使用 PHP CLI 运行代码也是如此)。但是,在我的大学提供的服务器上运行代码允许代码运行(在浏览器中和使用 CLI),我是否需要进行一些配置更改才能使代码正常运行?

<html>
    <head>
        <title>PHP Test</title>
    </head>
    <body>
        <?php
            echo "OCI Test<br>";
            $tns = "(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=abc.xyz.us-west-2.rds.amazonaws.com)(PORT=1521))(SOURCE_ROUTE = yes)(CONNECT_DATA=(SERVICE_NAME=orcl)))";
            echo "<pre>$tns</pre>'n";
            $username = "xxx";
            $password = "yyy";
            $db = @oci_connect($username, $password, $tns);
            // Gets to here before stopping
            if (!$db)
            {
                $e = oci_error();
                print_r(oci_error());
                trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);
            }
            $sql = "SELECT * FROM manufacturer";
            $stmt = oci_parse($db, $sql);
            if(OCIExecute($stmt))
            {
                while(OCIFetchInto($stmt, $row, OCI_RETURN_NULLS))
                {
                        echo $row[0]. "-" . $row[1]."<br>";
                }
            }
            oci_free_statement($stmt);
        ?>
    </body>
</html>

看起来您的数据库连接未正确初始化。您可能会从尝试捕获中受益。这可以阻止错误停止代码。看起来您假设它不会在以下条件语句中停止。

<html>
    <head>
        <title>PHP Test</title>
    </head>
    <body>
        <?php
            echo "OCI Test<br>";
            $tns = "(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=abc.xyz.us-west-2.rds.amazonaws.com)(PORT=1521))(SOURCE_ROUTE = yes)(CONNECT_DATA=(SERVICE_NAME=orcl)))";
            echo "<pre>$tns</pre>'n";
            $username = "xxx";
            $password = "yyy";
            try {
                $db = oci_connect($username, $password, $tns);
            } catch ('Exception $e) {
                $e = oci_error();
                print_r($e);
                throw $e;
            }
            $sql = "SELECT * FROM manufacturer";
            $stmt = oci_parse($db, $sql);
            if(OCIExecute($stmt))
            {
                while(OCIFetchInto($stmt, $row, OCI_RETURN_NULLS))
                {
                        echo $row[0]. "-" . $row[1]."<br>";
                }
            }
            oci_free_statement($stmt);
        ?>
    </body>
</html>

完成此操作后,希望错误会更有帮助。