0

I know there are other similar questions on the site, but I haven't been able to find a solution.

I have an RDS instance set up. We run our site on an EC2 instance.

I know MySQL works on the EC2 instance, because our current MySQL database is run on a different non-RDS server, and everything works fine.

I can connect to the RDS instance through MySQL workbench (I've approved my public IP address to connect).

I can connect to the RDS instance via phpMyAdmin, which is installed on the EC2 server.

However, I cannot connect to the RDS instance using PHP/MySQLi.

DEFINE ('DB_USER', '**user**'); DEFINE ('DB_PASSWORD', '**pass**'); DEFINE ('DB_HOST', '*************.rds.amazonaws.com'); if($dbc = @mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD)){ //DB connected, do nothing } else { echo 'Connection error'; echo mysqli_error(); exit(); } 

I'm getting no error output, nothing. It just echoes "Connection error".

I have the EC2 instance and RDS sharing a security group (although I can only edit inbound rules, not outbound, is this weird?), and have the EC2's public elastic IP allowed on the RDS security settings.

I'm lost!

2
  • Have you allowed the security group to access its own 3306 port? Your EC2 instance will be using an internal AWS IP to connect, not its Elastic IP. Commented Jul 9, 2014 at 16:02
  • I added access for all IP's (0.0.0.0) for the 3306 port, just to try it out... still doesn't work. Commented Jul 9, 2014 at 16:04

1 Answer 1

0

Try following:

<?php $link = mysql_connect('localhost', 'mysql_user', 'mysql_password'); if (!$link) { die('Could not connect: ' . mysql_error()); } echo 'Connected successfully'; mysql_close($link); ?> 

Replace localhost, mysql_user and mysql_password with your credentials.

OR

//conection: mysqli_connect("myhost","myuser","mypassw","mybd") or die("Error " . mysqli_error($link)); 

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.