title: How do I do MySQL queries on an RDS instance from an EC2 instance?
body: <p>I've been trying to set up a system where my database will be in an AWS RDS instance and my programs in a EC2 instance (seemingly very straightforward)</p>
  
  <p>For some reason following the results <a href="http://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_ConnectToInstance.html" rel="nofollow">here</a> have been pretty unhelpful.</p>
  
  <p>To clarify, what I'm looking for is some sample code to connect to a db and run mysql queries. So far my every attempt ends with my program trying to connect with my localhost mysql on my ec2 instance despite specifying the rds url.</p>
  
  <p>Here's my script,</p>
  
  <pre><code>&lt;?php
  $servername = "maindb.gibberish.us-east-1.rds.amazonaws.com";
  $username = "username";
  $password = "password";
  
  // Create connection
  $conn = mysqli_connect($servername, $username, $password);
  
  // Check connection
  if (mysqli_error($conn)) {
      die("Connection failed: " . mysqli_error($conn));
  }else{
          echo "connected successfully";    
  }
  ?&gt;
  </code></pre>