Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Will my PHP application work with Heroku's ClearDB MySql resource?

I am new to both php and Heroku and I have run into a bit of a problem. Currently my application is running fine on my xxamp testing server with mysql however when I try to host it on Heroku, there is no connection to the MySql server.

    Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] [2003] Can't connect to MySQL server on '127.0.0.1' (111)' in /app/www/pdo_testdb_connect.php:6 Stack trace: #0 /app/www/pdo_testdb_connect.php(6): PDO->__construct('mysql:host=127....', 'd2398h23d9d82j3', '8dj1292d3') #1 /app/www/all.php(6): testdb_connect() #2 {main} thrown in /app/www/pdo_testdb_connect.php on line 6 

Does ClearDB not work with PHP? Any suggestions would be much appreciated as I've sort of hit a brick wall.

like image 928
Ryan Fukushima Avatar asked Mar 02 '12 03:03

Ryan Fukushima


1 Answers

Here is the php integration of Cleardb with Heroku:

define ('DB_USER','xxxxxxxxxxxxxxxx');
define ('DB_PASSWORD','yyyyyyyyyyyyyy');
define ('DB_HOST','us-cdbr-east.cleardb.com');
define ('DB_NAME','heroku_zzzzzzzzzzzzzzzzzz');

Take the params by going in Git and typing heroku config. You will see a CLEARDB_DATABASE_URL

Here is how to decode it:

mysql://xxxxxxxxxxxxxx:[email protected]/heroku_zzzzzzzzzzzzzzz

Interestingly enough, in the official documentation they provide only a Ruby example but nothing about php.. http://devcenter.heroku.com/articles/cleardb

like image 130
Mark Belli Avatar answered Nov 14 '22 22:11

Mark Belli