我使用了MongoDB3.0和PHP版本5.3.5以及PHP驱动程序版本1.1.4。我试图将记录插入集合我得到致命错误类Mongo客户端不是fount
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";
?>
答案 0 :(得分:0)
这是因为使用http://php.net/manual/en/class.mongodb-driver-manager.php
而不喜欢这样:
$manager = new MongoDB\Driver\Manager("mongodb://localhost:2701");
此外mongo扩展不是mongodb扩展,也许你没有安装MongoDB扩展。查看this link了解详情
答案 1 :(得分:0)
自1.0.0发布以来,您应该使用MongoDB \ Driver \ Manage
最重要的是,传统驱动程序的MongoClient,MongoDB和MongoCollection类已被MongoDB \ Driver \ Manager类废弃,它是用于连接和执行查询,命令和写入操作的新网关。 / p>
来源:https://github.com/mongodb/mongo-php-driver/releases/tag/1.0.0