PLau Peter
PLau Peter

Reputation: 51

PHP connecting to AWS EC2 error

I connect to amazon ec2 through php. However, it says unknown MySQL server host. Thanks in advance!

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);

Warning: mysqli_connect() [function.mysqli-connect]: (HY000/2005): Unknown MySQL server host 'http://ec2-54-86-44-206.compute-1.amazonaws.com' (3) in /home/httpd/html/creasant.net/project15.creasant.net/peter/include/test.php

Upvotes: 0

Views: 100

Answers (2)

Cythral
Cythral

Reputation: 75

MySQL doesn't connect over HTTP, so you will want to remove http:// from the DB_SERVER constant:

define("DB_SERVER", "ec2-54-86-44-206.compute-1.amazonaws.com");

Alternatively, you could connect using the IP address instead:

define("DB_SERVER", "54.86.44.206");

Upvotes: 1

Tauheed
Tauheed

Reputation: 1

don't use http://ec2-54-86-44-206.compute-1.amazonaws.com use localhost as DB is local to you

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);

Upvotes: 0

Related Questions