警告:mysqli_connect():( 28000/1045):在Cpanel上

时间:2014-07-17 14:10:21

标签: php mysql file cpanel

我在cPanel上部署我的网站后遇到了这个问题。重要的是它在localhost和amazon-EC2服务器上运行良好。因此,在您将此问题标记为重复之前,请完全理解。

我的功能是,当用户提交表单时,会在服务器上创建一个php文件,其中包含sql查询(计算该文件的点击次数)和其他与功能相关的动态内容。但是当该文件在浏览器中执行时,它会发出警告

Warning: mysqli_connect(): (28000/1045): Access denied for user 'socialle_slcm'@'localhost' (using password: YES)` 

此问题仅在cPanel上发生。我检查了文件权限。但一切都很好。请帮忙。

我的代码是

create.php(这会创建user.php文件)

<?php
    $txt = "
        <?php
           ob_start();
        ?>
        <html>
        <body>
        <?php
        ob_start();
        \$con=\mysqli_connect(\"localhost\",\"social\",\"sslc123\",\"socialle_slcm\");
        \$file_id = ".$file_id.";
        if (!empty(\$_SERVER['HTTP_CLIENT_IP'] ) ) {    
        \$ip = \$_SERVER['HTTP_CLIENT_IP'];
        } elseif (!empty(\$_SERVER['HTTP_X_FORWARDED_FOR'] ) ) {
        \$ip = \$_SERVER['HTTP_X_FORWARDED_FOR'];
        } else {
        \$ip = \$_SERVER['REMOTE_ADDR'];
        }
        \$date = \date('Y-m-d H:i:s');
        \$result = \mysqli_query(\$con,\"SELECT  count(visitor_id) as count_ip FROM visitors where file_id = '\$file_id' and ip_address = '\$ip'\");
        while(\$row = \mysqli_fetch_array(\$result))
        {
        \$count_ip = \$row['count_ip'];
        }
        if(\$count_ip == 0)
        {
        \$result = \mysqli_query(\$con,\"INSERT INTO visitors (`file_id`,`ip_address`,`last_visited`) VALUES ('\$file_id','\$ip','\$date')\");
        }
        else
        {
        \$result = \mysqli_query(\$con,\"SELECT count FROM visitors where file_id = '$file_id' and  ip_address = '\$ip'\");
        while(\$row = \mysqli_fetch_array(\$result))
        {
        \$count = \$row['count'];
        }
        \$count++;

        \$result = mysqli_query(\$con,\"UPDATE visitors SET count = \$count,last_visited = '\$date' WHERE file_id = '\$file_id' and ip_address = '\$ip'\");
        }
        header('Location: ".$landing_page."');
        ?>
        </body>
        </html>
    ";
    fwrite($myfile, $txt);
    fclose($myfile); 

user.php的

<?php
ob_start();
?>
<html>
<body>
<?php
ob_start();
$con=\mysqli_connect("localhost","social","sslc123","socialle_slcm");
$file_id = 425;
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {   
$ip = $_SERVER['HTTP_CLIENT_IP'];
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
$ip = $_SERVER['REMOTE_ADDR'];
}
$date = \date('Y-m-d H:i:s');
$result = \mysqli_query($con,"SELECT  count(visitor_id) as count_ip FROM visitors where file_id = '$file_id' and ip_address = '$ip'");
while($row = \mysqli_fetch_array($result))
{
$count_ip = $row['count_ip'];
}
if($count_ip == 0)
{
$result = \mysqli_query($con,"INSERT INTO visitors (`file_id`,`ip_address`,`last_visited`) VALUES ('$file_id','$ip','$date')");
}
else
{
$result = \mysqli_query($con,"SELECT count FROM visitors where file_id = '425' and  ip_address = '$ip'");
while($row = \mysqli_fetch_array($result))
{
$count = $row['count'];
}
$count++;

$result = mysqli_query($con,"UPDATE visitors SET count = $count,last_visited = '$date' WHERE file_id = '$file_id' and ip_address = '$ip'");
}
header('Location: http://rackinfotech.com');
?>
</body>
</html>

这完全适用于localhost和amazon-EC2服务器,仅在cpanel上出现问题。

2 个答案:

答案 0 :(得分:0)

您可以尝试使用服务器的IP地址,而不是使用localhost。此外,与使用cPanel的版本相比,您的Amazon服务器的MySQL版本是否不同?

答案 1 :(得分:0)

尤里卡!!!! 通过删除不必要的新行和HTML代码

来解决问题

这样创建的文件包含以下代码,并且完美运行。

<?php
ob_start();
$con=\mysqli_connect("localhost","social","sslc123","socialle_slcm");
$file_id = 425;
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {   
$ip = $_SERVER['HTTP_CLIENT_IP'];
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
$ip = $_SERVER['REMOTE_ADDR'];
}
$date = \date('Y-m-d H:i:s');
$result = \mysqli_query($con,"SELECT  count(visitor_id) as count_ip FROM visitors where file_id = '$file_id' and ip_address = '$ip'");
while($row = \mysqli_fetch_array($result))
{
$count_ip = $row['count_ip'];
}
if($count_ip == 0)
{
$result = \mysqli_query($con,"INSERT INTO visitors (`file_id`,`ip_address`,`last_visited`) VALUES ('$file_id','$ip','$date')");
}
else
{
$result = \mysqli_query($con,"SELECT count FROM visitors where file_id = '425' and  ip_address = '$ip'");
while($row = \mysqli_fetch_array($result))
{
$count = $row['count'];
}
$count++;

$result = mysqli_query($con,"UPDATE visitors SET count = $count,last_visited = '$date' WHERE file_id = '$file_id' and ip_address = '$ip'");
}
header('Location: http://rackinfotech.com');