在Windows上安装phpMongo驱动程序 [英] Install phpMongo Drivers on windows
问题描述
我想从PHP 5.6运行mongodb.我已经从 https://github.com/mongodb/mongo-php-library.我运行命令composer require "mongodb/mongodb=^1.0.0"
,那么zip
文件呢?有什么简单的安装方法吗?
I want to run mongodb from PHP 5.6. I have downloaded it from https://github.com/mongodb/mongo-php-library. I run the command composer require "mongodb/mongodb=^1.0.0"
and what about the zip
file? Is there any easy method to install it?
我运行这段代码
<?php
require 'vendor/autoload.php';
$connection = new MongoDB();
?>
并出现错误:
致命错误:在C:\ wamp64 \ www \
Fatal error: Class 'MongoDB' not found in C:\wamp64\www\
new MongoDB\Client("mongodb://localhost:27017");
可以正常工作,但保存文档$collection->insert($document);
会出现错误insert method is not found
works fine but for saving the document $collection->insert($document);
gives the error insert method is not found
推荐答案
如果文件在供应商图中,则通过composer进行的安装可能会顺利进行.我认为现在的问题是您要创建一个不存在的类的实例. MongoDB不是名称空间而不是类吗?
If the files are in the vendor map the installation via composer went probably well. I think the problem now is that you want to create an instance of a class that doesn't exist. Isn't MongoDB the namespace and not the class?
来自MongoDB的文档:
From the documentation of MongoDB:
$database = (new MongoDB\Client)->selectDatabase('db_name');
请参阅有关名称空间的文档: http://php.net/manual/zh/language.namespaces.php
See the documentation on namespaces: http://php.net/manual/en/language.namespaces.php
-编辑-
对于插入,您应根据文档使用insertOne()
: http://mongodb.github.io/mongo-php-library/classes/collection/#insertone
For inserting you should use insertOne()
according to the documentation: http://mongodb.github.io/mongo-php-library/classes/collection/#insertone
function insertOne($document, array $options = []): MongoDB\InsertOneResult
这篇关于在Windows上安装phpMongo驱动程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!