I’ve a PHP app to be hosted on heroku. The basic functionality of the app is to collect some data from users (through browsers) & store those in a database (since this is a PHP app, the database modifications must be made through PHP only). Now I’ve enabled the MongoLab addon from heroku control panel & created database, user, & sample collection into that database. I’ve deployed my code to heroku via git. Following is the content of a file db.php located inside the root folder of the app
<?php
try {
$user = 'my user name';
$pass = 'my password';
$app = 'my app name';
$col = 'sample collection';
echo 'connecting ...';
$connection = new Mongo('mongodb://'.$user.':'.$pass.'@ds034512.mongolab.com:34512/'.$app);
echo 'connected';
$database = $connection->selectDB($app);
$collection = $database->selectCollection($col);
}
catch(MongoConnectionException $e) {
die("Failed to connect to database ".$e->getMessage());
}
?>
now whenever I’m trying to execute the file on the heroku server itself (by caling the url http://my-app-name.herokuapp.com/db.php from my local browser) it’s showing
“connecting …” & in the console there is an error message “NetworkError: 500 Internal Server Error – http://my-app-name.herokuapp.com/db.php“
Can anyone suggest me any idea on how this database integration be done for apps hosted on heroku ?
You didn’t include the mongodb driver. This gist has all the instructions.
https://gist.github.com/1288447