请帮忙检查连接,我已经坚持了几个小时了=(

时间:2013-06-05 08:51:17

标签: php mysql

有人能指出这是否有任何错误?我被告知有错误,我只能通过localhost连接,而不是通过这个主机名..

我被告知我在db.class.php中设置的密码是错误的。部分代码如下所示。理解!

function __construct($hostname = "192.xx.x.45", $username = "test", $password = "tests", $database = "testing", $prefix = "prefix_", $connector = "mysqli") {
    $this->hostname = !empty($hostname) ? $hostname : "";
    $this->username = !empty($username) ? $username : "";
    $this->password = !empty($password) ? $password : "";
    $this->database = !empty($database) ? $database : "";
    $this->prefix = !empty($prefix) ? $prefix : "";
    $this->connector = !empty($connector) ? $connector : "mysqli";
}

if ($this->config->connector == "mysqli") { 
$this->connection = mysqli_connect($this->config->hostname, $this->config->username, $this->config->password);
$this->selectdb = mysqli_select_db($this->connection, $this->config->database);
}

1 个答案:

答案 0 :(得分:0)

根据您收到的错误消息,您的问题是您用于连接MySQL的数据库用户没有从您正在访问数据库的服务器的IP连接的权限。

您需要修改数据库用户,以允许它从任何IP或您服务器的IP连接到MySQL数据库。如上所述,请查看MySQL手册:

http://dev.mysql.com/doc/refman/5.0/en/account-names.html

此外,您需要确保MySQL服务器的防火墙允许从其他服务器到MySQL端口的连接(默认情况下为3306)。