0

I have a database connection file in my web application and for some reason the server is trying to connect to the location of: ***.**.**.215 for the ip address rather than: ***.**.**.222 which is what is typed in the file. The code is below:

<?php 

   // Configure the following items to match your database! 

     // Database Location 
     $location = '***.**.**.222'; 

     // Database Name 
     $name = '';

     // Database Username 
     $username = ''; 

     // Database Password 
     $Password = ''; 

  // Do not alter anything beyond this line! 

     // Create connection
     $con=mysqli_connect($location,$username,$password,$name);

     // Check connection
     if (mysqli_connect_errno($con))
     {
        echo "Failed to connect to MySQL: " . mysqli_connect_error();
     }

?>

Google Chrome shows this exact error message: I removed the credentials from it.

Warning: mysqli_connect() [function.mysqli-connect]: (28000/1045): Access denied for user 'username'@'***.**.**.215' (using password: NO) in /home/www/hiddenforsecurity/shop/config/connect.php on line 20
Failed to connect to MySQL: Access denied for user 'username'@'***.**.**.215' (using password: NO)

I'm not sure what in the world to do or what is wrong, when I replace $location in the $con with the actual ip address, it works perfect. It's just when I use the variable $location that it doesn't work.

I removed important private credentials from this question. Sorry hackers.

4

2 回答 2

3
// Database Password 
     $Password = ''; 
// Create connection
     $con=mysqli_connect($location,$username,$password,$name);

将大写的 $Password 更改为 $password。

于 2013-10-09T16:25:14.100 回答
0

您在一个 IP 地址为 *.215 的客户端上,并且您正在尝试使用 IP 地址 *.222 连接到 MySQL 服务器,因此请确保 MySQL 服务器上的用户“$username”被允许从该 IP 进行连接*.215 您正在使用。(默认情况下,每个用户只能从本地 127.0.0.1 连接)。

您尝试建立的连接不使用密码,请注意您在 mysqli_connect(...) 函数中使用的变量是$password并且在$Password上方的配置中(第一个字母大写)。

我建议您检查错误日志文件(如果您使用的是 apache,则它是 httpd 文件夹中的 error.log),因为在该文件中记录了所有警告和错误,并且可以帮助您解决问题,在这种情况下可能存在像这样的东西:

变量$password在nnn行的page.php中未定义。

于 2013-10-09T16:33:19.340 回答