dongpu5874
2016-07-11 16:47
浏览 82
已采纳

Mysql服务器不再与servername连接

I was connected with my server using my server name.

<?php
ini_set('default_charset', 'UTF-8');

$servername = "my server name here";
$username = "xxxxx";
$pass = "xxxx";
$dbname = "xxxx";


$conn = mysqli_connect ($servername, $username, $pass, $dbname);
if(!$conn) {
die("Connection faild: ".mysqli_connect_error());   
}

$conn->query("SET NAMES utf8");


?>

All my aplications was working and now stopped. Now is only connecting if i use my server ip.

There are the errors **Warning: mysqli_connect(): (HY000/2002): php_network_getaddresses: getaddrinfo failed

Connection faild: php_network_getaddresses: getaddrinfo failed

**

When i connect on the database with my login and pssword in my host provider it enters fine,nothing changed.

Btw im using xampp.

Anyone knows why this is happening?

图片转代码服务由CSDN问答提供 功能建议

我使用服务器名称与服务器连接。

 &lt;?php 
ini_set('default_charset','UTF-8'); 
 
 $ servername =“我的服务器名称在这里”; 
 $ username =“xxxxx”; 
 $ pass =“xxxx”  ; 
 $ dbname =“xxxx”; 
 
 
 $ conn = mysqli_connect($ servername,$ username,$ pass,$ dbname); 
if(!$ conn){
die(“Connection faild:”  .mysqli_connect_error());  
} 
 
 $ conn-&gt; query(“SET NAMES utf8”); 
 
 
?&gt; 
   
 
 

我的所有申请 工作,现在停止。 如果我使用我的服务器IP,现在只连接。

有错误 **警告:mysqli_connect():( HY000 / 2002):php_network_getaddresses :getaddrinfo失败

Connection faild:php_network_getaddresses:getaddrinfo failed

**

当我连接到 在我的主机提供商中使用我的登录名和pssword的数据库 it输入正常,没有任何变化。

请使用xampp。

任何人都知道为什么这是 发生了什么?

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dshu1235 2016-07-11 16:57
    已采纳

    Normally, using xampp in Windows, we will set server name be "localhost"

    $servername = "localhost";
    

    If you want other name, please set in hosts file:

    C:\Windows\System32\drivers\etc\hosts

    127.0.0.1 my_domain_name.com
    

    And add "my_domain_name.com" (for example) into $servername variable

    已采纳该答案
    打赏 评论
  • douliang2935 2016-07-11 16:51

    Use that

    $db_conx = mysqli_connect("localhost", "root", "", "project2");
    
    
    // Evaluate the connection
    if (mysqli_connect_error()) {
        echo mysqli_connect_error();
        exit();
    } 
    
    打赏 评论

相关推荐 更多相似问题