PDO :: __ construct():php_network_getaddresses:getaddrinfo失败:名称或服务未知 [英] PDO::__construct(): php_network_getaddresses: getaddrinfo failed: Name or service not known

查看:511
本文介绍了PDO :: __ construct():php_network_getaddresses:getaddrinfo失败:名称或服务未知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关于堆栈溢出的这个主题有很多问题,但是没有一个与我的情况相符.

There are tons of questions asked on this topic on Stack Overflow, but none of them matches my case.

我正在使用Lampp和PHP 5.4.7,直到我用PHP开发了我的第一个PDO程序时,它运行良好.

I am using Lampp with PHP 5.4.7 and it was running fine until I developed my first PDO program in PHP.

当我使用

$con=new PDO("mysql:host='localhost';dbname='data';charset=utf8",'root','');

对于连接,我会收到此错误.是否需要在php.ini中激活某些内容?

for connection I get this error.Do I need to activate something in php.ini?

推荐答案

"mysql:host ='localhost'; dbname ='data'; charset = utf8"

"mysql:host='localhost';dbname='data';charset=utf8"

您的DSN格式错误,不应在其中添加这些引号.这是正确的格式

Your DSN format is wrong, it shouldn't have those quotes in there. This is the right format

 //$con=new PDO($dsn, $user, $password);
 $con=new PDO('mysql:dbname=testdb;host=127.0.0.1','root',''); 

请参见手册

这篇关于PDO :: __ construct():php_network_getaddresses:getaddrinfo失败:名称或服务未知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆