Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/242.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么带有mysqli的php7.4只在根目录下运行?_Php_Mysqli - Fatal编程技术网

为什么带有mysqli的php7.4只在根目录下运行?

为什么带有mysqli的php7.4只在根目录下运行?,php,mysqli,Php,Mysqli,最近,我的托管网站(HostGator)将我的网站的PHP从5.4升级到7.4。在5.4版中正常工作后,包含php和mysqli语句的页面失败。代码如下: <body> <?php include("menu_primary.html");?> Some text <?php $servername = "localhost"; $username = "my_username";

最近,我的托管网站(HostGator)将我的网站的PHP从5.4升级到7.4。在5.4版中正常工作后,包含php和mysqli语句的页面失败。代码如下:

<body>
<?php include("menu_primary.html");?>
Some text
<?php 
    $servername = "localhost";
    $username = "my_username";
    $password = "my_password";
    $database = "my_database";
    
    // Create connection
    $link = mysqli_connect($servername, $username, $password, $database);
        // Check connection
        if (!$link) {
            die("Connection failed: " . mysqli_connect_error());
        }   

一些文本
可以正常执行。 经过多次尝试和错误,我想到了将整个PHP文件从文件夹
/public\u html/my\u app
移动到文件夹
/public\u html
。然后一切又恢复了正常
这两个文件是在从PHP5.4升级到PHP7.4的过程中编辑的
问题:在
/public\u htmnl/.htaccess
/public\u html/php.ini
文件中,我是否必须做些什么才能允许嵌入式php在
/public\u html
的下属目录中执行?
谢谢你看这个。

过了很多天,我从我的托管公司得到了一个答案。文件.htaccess是问题所在。当站点从5.4升级到7.4时,添加了以下行:

suPHP_ConfigPath /home2/susanna
公用html文件夹从属于该路径。他们的升级支持注释掉了添加的整个部分:

#<IfModule mod_suphp.c>
# suPHP_ConfigPath /home2/susanna
 #<Files php.ini>
#   order allow,deny
#   deny from all
# </Files>
#</IfModule>
#
#suPHP\u配置路径/home2/susanna
#
#命令允许,拒绝
#全盘否定
# 
#

现在,可以从从属目录调用PHP代码(在PHP7.4上执行)。

该代码没有明显的错误,在7.4中,无论文件位于何处,都应该可以使用相同的代码。请详细说明它是如何失败的(因为它可能意味着许多不同的事情)。到底发生了什么?你在屏幕上看到错误了吗?你检查错误日志了吗?为什么要编辑.htaccess?升级PHP不需要对该文件进行任何更改,因为它是Apache(web服务器)的配置文件。请确保已启用mysqli错误报告生成的错误为:致命错误:未捕获错误:调用/home2/susanna/public_html/new_parishioner/input1_test.PHP:55堆栈跟踪:#0{main}中未定义的函数mysqli_connect()第55行的/home2/susanna/public_html/new_parishioner/input1_test.php中抛出了$link=statement,我没有编辑.htaccess或php.ini文件。托管公司做到了。过了一段时间才发现错误,因此备份被删除。然而,.htaccess文件中有一行似乎启用了php7.4:AddHandler应用程序/x-httpd-ea-php74.php.php7.phtml