2016-06-05 22:32
浏览 85

如何从php连接到mongodb [openshift]?

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


// connect to MongoDB

// 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

//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 '*********************************';
  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题