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

Php 警告:mysqli_connect():(28000/1045):在Cpanel上,php,mysql,file,cpanel,Php,Mysql,File,Cpanel,我在cPanel上部署了我的网站后遇到了这个问题。重要的一点是,它可以在本地主机和amazon-EC2服务器上完美地工作。所以,在你将这个问题标记为重复问题之前,请彻底理解它 我的功能是,当用户提交表单时,会在服务器上创建一个php文件,其中包含sql查询(计算对该文件的点击次数)和其他与功能相关的动态内容。但当该文件在浏览器中执行时,它会发出警告 Warning: mysqli_connect(): (28000/1045): Access denied for user 'socialle_

我在cPanel上部署了我的网站后遇到了这个问题。重要的一点是,它可以在本地主机和amazon-EC2服务器上完美地工作。所以,在你将这个问题标记为重复问题之前,请彻底理解它

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

Warning: mysqli_connect(): (28000/1045): Access denied for user 'socialle_slcm'@'localhost' (using password: YES)` 
此问题仅在cPanel上发生。我检查了文件权限。但一切都很好。请帮忙

我的代码是

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


您可以尝试使用服务器的IP地址,而不是使用
localhost
。另外,与使用cPanel的服务器相比,您的亚马逊服务器的MySQL版本是否有所不同?

Eureka!!!! 通过删除不必要的新行和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');

希望这不是你真正的密码版本的mysql没有问题。因为网站中的其他查询工作正常。我将尝试使用服务器的ip地址。
<?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>
<?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');