【问题标题】:PDO connection Error to the database与数据库的 PDO 连接错误
【发布时间】:2012-11-22 01:00:51
【问题描述】:

我试图在我的本地机器上运行我的项目,但它带来了以下错误:

ERRNO:2
文本:PDO::__construct() [pdo.--construct]: php_network_getaddresses: getaddrinfo failed: The requested name is valid, but no data of the requested type was found. LOCATION: C:\xampp\htdocs\rsecrets\business\database_handler.php, line 25, at December 4, 2012, 12:46 pm

我是如何定义连接的:

define('DB_PERSISTENCY', 'true');
define('DB_SERVER', 'localhost');
define('DB_USERNAME', 'root');
define('DB_PASSWORD', '');
define('DB_DATABASE', 'xxyy');
define('PDO_DSN', 'mysql:host=' . DB_SERVER . ';dbname=' . DB_DATABASE);

这是 database_handler.php 中第 25 行的内容:

 self::$_mHandler =
          new PDO(PDO_DSN, DB_USERNAME, DB_PASSWORD,
                  array(PDO::ATTR_PERSISTENT => DB_PERSISTENCY));

我没有得到什么?

【问题讨论】:

  • 你可以使用命令行连接:mysql -u root -p -d xxyy -h localhost 吗?

标签: php database pdo


【解决方案1】:

您的主机文件中可能没有localhost 的有效 IPv4 条目。

以管理员身份运行notepad.exe并编辑%SystemRoot%\system32\drivers\etc\hosts

确保出现以下行(没有前导 #

127.0.0.1    localhost

【讨论】:

    猜你喜欢
    • 2014-10-31
    • 2016-04-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-28
    • 1970-01-01
    • 2013-04-22
    • 2013-05-14
    相关资源
    最近更新 更多