Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connect to Amazon RDS with PHP

I am trying to connect my RDS Instance with my PHP connection file.

This is what I have in my file:

define('DB_SERVER', 'localhost');
define('DB_USERNAME', 'User Name');
define('DB_PASSWORD', 'Password');
define('DB_DATABASE', 'DATABASE');

$connection = mysql_connect(DB_SERVER, DB_USERNAME, DB_PASSWORD) or die(mysql_error());
$database = mysql_select_db(DB_DATABASE) or die(mysql_error());

I replaced localhost with my endpoint (rds thing) url, username and password with my RDS Instance user and pass and database name the one I've set when I created the instance. But it doesn't seem to work.

Is there anything else I have to do that I am not aware of or should it work?

like image 685
jQuerybeast Avatar asked Mar 06 '12 11:03

jQuerybeast


1 Answers

RDS instances do not have a static IP address attached to them, you always use the endpoint for the host. For example:

database1.jlsdfjhgsdf.us-east-1.rds.amazonaws.com

If you are connecting to the instance with a username other than the root database account, you will need to grant the user privileges.

Check security group settings. If you are connecting from another EC2 instance on Amazon you will need to attach that security group. If you are trying to connect from outside AWS, you will need to whitelist the IP address you are accessing from.

like image 158
jaredstenquist Avatar answered Oct 11 '22 13:10

jaredstenquist