我通过php连接到amazon ec2。但是,它说未知的MySQL服务器主机。提前谢谢!
define('DB_SERVER', 'http://ec2-54-86-44-206.compute-1.amazonaws.com');
define('DB_USERNAME', 'root');
define('DB_PASSWORD', 'PW');
define('DB_DATABASE', 'DB');
$connection = mysqli_connect(DB_SERVER, DB_USERNAME, DB_PASSWORD);
警告:mysqli_connect()[function.mysqli-connect] :( HY000 / 2005):/home/httpd/html/creasant.net/project15中未知的MySQL服务器主机“http://ec2-54-86-44-206.compute-1.amazonaws.com”(3)。 creasant.net/peter/include/test.php
答案 0 :(得分:1)
MySQL不通过HTTP连接,因此您需要从DB_SERVER常量中删除http://:
define("DB_SERVER", "ec2-54-86-44-206.compute-1.amazonaws.com");
或者,您可以使用IP地址进行连接:
define("DB_SERVER", "54.86.44.206");
答案 1 :(得分:0)
不要使用http://ec2-54-86-44-206.compute-1.amazonaws.com使用 localhost ,因为数据库是您的本地
define('DB_SERVER', 'localhost');
define('DB_USERNAME', 'root');
define('DB_PASSWORD', 'PW');
define('DB_DATABASE', 'DB');
$connection = mysqli_connect(DB_SERVER, DB_USERNAME, DB_PASSWORD);