title: remote mysql connection using private key in php
body: <p>I checked other threads but couldnt find an answer for this specific question.</p>
  
  <p>To make things easier, here is the setup I use to connect to db using mysqlworkbench</p>
  
  <pre><code>ssh hostname :somehostname.com:22
  ssh username: ec2-user
  ssh password : my private key password
  ssh keyfile /Users/me/.ssh/id_rsa   : this is my private key stored on my local machine
  mysql hostname: qa.cbhasfasupvz.us-east-1.rds.amazonaws.com
  port: 3306
  username: root
  passowrd : mysql database password
  </code></pre>
  
  <p>my public key is set on the server already and I can connect to the database through mysqlworkbench.</p>
  
  <p>But i need to connect to this database using the private key I have, from another server through php. So i can make some queries and present them in html tables etc.</p>
  
  <p>My guess is to create a php file on my server, 
  store my private key somewhere on this server safely.
  connect to database using the private key, db location, password etc.</p>
  
  <p>I am asking the connection code I need in that php file. This is what I would use if the db was located on the local server</p>
  
  <pre><code>mysql_connect("localhost", "root", "pass") or die(mysql_error()) ;
  mysql_select_db("my_db") or die(mysql_error()) ;
  </code></pre>