Im trying to connect to mongodb. Use openshift hosting. Code u can see in footer. I tried to enter username,pass before $env and db_name after $env, but nothing happens. I get 500 error from webserver. Can somebody tell me whats wrong and how to fix it? rockmongo works fine, so mistake in my code, i think. i tried lot of combination of it
<?php
// connect to MongoDB
$m = new MongoClient("mongodb://$OPENSHIFT_MONGODB_DB_HOST:$OPENSHIFT_MONGODB_DB_PORT");
// select a database
$db = $m->comedy;
// select a collection
$collection = $db->cartoons;
$document = array(
"title" => "Hibernate and MongoDB",
"author" => "Anghel Leonard"
);
//insert a new document
$collection->insert($document);
//returns a cursor for the search results
$cursor = $collection->find();
// iterate through the results
foreach ($cursor as $document) {
echo '"_id": '.$document["_id"]."<br />";
echo '"title": '.$document["title"]."<br />";
echo '"author": '.$document["author"]."<br />";
echo '*********************************';
}
?>