2015-07-14 06:55
浏览 50


function MongoConnect($username, $password, $database, $host) {
    $con = new Mongo("mongodb://{$username}:{$password}@{$host}"); // Connect to Mongo Server
    $db = $con->selectDB($database); // Connect to Database
$document = array( "name" =>"Calvin and Hobbes");
// find everything in the collection
$cursor = $collection->find();
// iterate through the results
foreach ($cursor as $document) {
    echo $document["name"] . "

I had installed MONGO DB and tried to test my DB, but I am getting an ERROR

"Internal Server Error 500"

And also my Test.php file have my own content called Hello World, but if I had run the TEST.php file it displays Nothing. My DB table is not accessing and I wasn't able to retrieve data from my Database. So Kindly help me out here.

图片转代码服务由CSDN问答提供 功能建议

 $ username ='root'; 
 $ password ='xyz'  ; 
 $ database ='abc'; 
 $ host ='localhost'; 
函数MongoConnect($ username,$ password,$ database,$ host){
 $ con = new Mongo(“mongodb:// {  $用户名}:{$密码} @ {$主机}“);  //连接到Mongo Server 
 $ db = $ con&gt; selectDB($ database);  //连接到数据库
 $ collection = $ db-&gt; movie; 
 $ document = array(“name”=&gt;“Calvin and Hobbes”); 
 $ collection-&gt; insert($ 文档); 
 $ cursor = $ collection-&gt; find(); 
foreach($ cursor as $ document){
 echo $ document [  “名称”] 。  “

我安装了MONGO DB并试图测试我的数据库,但是我收到了错误


还有我的 Test.php < / code> 文件有我自己的内容叫做 Hello World ,但是如果我运行了 TEST.php 文件,它就显示Nothing。 我的数据库表不是 访问,我无法从我的数据库中检索数据。 所以请在这里帮助我。

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • drt5813 2015-07-14 07:15

    There can be several things wrong.
    First - is Mongo driver installed?
    Second - your MongoConnect function have no effect. You are defining it and not calling. Plus even if you would call it there would be no effect as $db is only in function scope and not outside. Third - because function MongoConnect have no effect "$collection=$db->movie;" will result in problem as $db is not defined.
    Consult on how to insert data in collection.

    打赏 评论
  • doutan3192 2015-07-14 07:13

    Internal Server Error only occured when misspelled in code or some of function called wrongly. Please review ur code.

    打赏 评论

相关推荐 更多相似问题