phpmysqlopenshiftopenshift-cartridgeopenshift-php-cartidges

Error when connecting one app to a different app's database


I was following the instructions in this post:

https://blog.openshift.com/sharing-database-across-applications/

And I have two apps running successfully, with data in my production app, with my reports app up trying to query the production database. From my production app, I am able to grab the HOST, PORT, USERNAME, AND PASSWORD.enter image description here

On my reports app, I have a simple test script to test connectivity:

$db = mysql_connect('127.7.171.129:3306', 'USER','PW');

if (!$db) {
  echo "Could not connect to database: " . mysql_error();
} else {
  echo "Connected to database.<br>";
}

The error I am getting is:

Could not connect to database: Lost connection to MySQL server at 'reading initial communication packet', system error: 113

Any help would be appreciated.


Solution

  • You need to have created your production application as a scaled application so that you can access it's database from your other applications (as the database will then be on it's own gear). Since your database connection is using port 3306, it is probably not a scaled application, as the port number would be something different, and the host would be a FQDN instead of an ip address.