php getaddrinfo失败:"在数据库查找期间发生了不可恢复的错误。"

时间:2014-08-31 12:08:52

标签: php mysql pdo

非常感谢您的帮助请:)我的PDO连接上一直出现错误:警告:PDO :: __ construct():php_network_getaddresses:getaddrinfo failed:数据库中发生了不可恢复的错误查找。

以下是代码:

<?php
class Database{
public $dbserver = '';
public $username = '';
public $password = '';
public $database = '';
public $db = '';
public function __construct(){
$this->dbserver = 'localhost';
$this->username = 'tiffinie';
$this->password = 'pword';
$this->database = 'practicedb';
$this->db = new PDO("mysql:host=".$this->dbserver.";dbname=".$this->database, $this->username, $this->password);
}
public function dbselect($table, $select, $where=NULL){
}
public function dbadd($tablename, $insert, $format){
}
public function dbupdate($tablename, $insert, $where){
}
}
?>

2 个答案:

答案 0 :(得分:3)

托管您应用的服务器可能不知道如何解析“localhost”。

请参阅hosts文件。

您可以通过将“localhost”替换为“127.0.0.1”

来解决此问题

答案 1 :(得分:0)

在http配置文件中定义SQL服务器的名称,或尝试使用类似127.0.0.1的IP地址

确保数据库正在运行