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


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!

  • 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. – ceejayoz Jul 9 '14 at 16:02
  • I added access for all IP's ( for the 3306 port, just to try it out... still doesn't work. – Erik Jul 9 '14 at 16:04

Try following:

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

Replace localhost, mysql_user and mysql_password with your credentials.


mysqli_connect("myhost","myuser","mypassw","mybd") or die("Error " . mysqli_error($link)); 
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.