我遇到这个错误警告:mysql_connect():php_network_getaddresses:getaddrinfo失败:没有这样的主机是已知的。

时间:2014-07-02 08:21:38

标签: php

我的错误是

`

 if($_SERVER['HTTP_HOST']=="localhost" || $_SERVER['HTTP_HOST']=="server"  )
{ 
// Config setting for localhost.
define("DBSERVER","localhost");
define("DBNAME","raj12");
define("DBUSER","root");
define("DBPASS","");   
$connect=   mysql_connect("DBSERVER","DBUSER","DBPASS") or die(mysql_error()."cannot             connect local");

} 
else
{ // Config setting for live server.
define(DBSERVER,"localhost");
define(DBNAME,"raj12");
define(DBUSER,"root@123");
define(DBPASS,"root@123");
mysql_connect(DBSERVER,DBUSER,DBPASS) or die("cannot connect server");

}

mysql_select_db(DBNAME)or die("error in selecting database");
include("db.class.php");
$obj=new DB(DBNAME,DBSERVER,DBUSER,DBPASS);

?>` 

警告:mysql_connect():php_network_getaddresses:getaddrinfo失败:没有这样的主机。在第14行的C:\ xampp \ htdocs \ rajsons \ lib \ config.php ##

2 个答案:

答案 0 :(得分:3)

您正在传递字符串文字而不是您定义的常量。

mysql_connect("DBSERVER","DBUSER","DBPASS")

删除引号。

答案 1 :(得分:1)

改为:

if($_SERVER['HTTP_HOST']=="localhost" || $_SERVER['HTTP_HOST']=="server"  )
{ 
    // Config setting for localhost.
    define(DBSERVER, "localhost");
    define(DBNAME, "raj12");
    define(DBUSER, "root");
    define(DBPASS, "");   
    $connect = mysql_connect(DBSERVER, DBUSER, DBPASS) or die(mysql_error() . "cannot connect local");
} 

最好使用mysqli代替mysql