2017-01-23 167 views
0

我已經使用MongoDB3.0與PHP版本5.3.5和PHP驅動程序版本1.1.4。我試圖插入記錄收集我得到致命錯誤類蒙戈客戶端沒有發現那位致命錯誤:類'MongoClient'找不到?

insert.php

<?php 
     // connect to mongodb 
    $m = new MongoClient("mongodb://localhost:27017"); 
    echo "Connection to database successfully"; 

    // select a database 
    $db = $m->sample; 
    echo "Database mydb selected"; 
    $collection = $db->testcoll; 
    echo "Collection selected succsessfully"; 

    $document = array( 
     "title" => "MongoDB", 
     "description" => "database", 
     "likes" => 100, 
     "url" => "http://www.tutorialspoint.com/mongodb/", 
     "by", "tutorials point" 
    ); 

    $collection->insert($document); 
    echo "Document inserted successfully"; 


?> 

我還附上PHP驅動程序信息enter image description here

+0

嘗試使用MongoDB的'\驅動程序\ Manager' – Robert

+0

再次得到了'致命錯誤:類 '的MongoDB \驅動程序\經理' 找不到'@Robert –

回答

0

正是因爲這個類中刪除嘗試使用http://php.net/manual/en/class.mongodb-driver-manager.php

,而不是像這樣:

$manager = new MongoDB\Driver\Manager("mongodb://localhost:2701"); 

也mongo擴展不是mongodb擴展也許你沒有安裝MongoDB擴展。檢查this link更多細節

0

由於1.0.0版本中,您應該使用MongoDB的\驅動程序\管理

最顯著,傳統驅動器的MongoClient,MongoDB的,和MongoCollection類已廢棄由MongoDB的\驅動程序\ Manager類,這是連接和執行查詢,命令和寫入操作的新網關。

來源:https://github.com/mongodb/mongo-php-driver/releases/tag/1.0.0

相關問題