[英]Install phpMongo Drivers on windows
I want to run mongodb from PHP 5.6. 我想从PHP 5.6运行mongodb。 I have downloaded it from https://github.com/mongodb/mongo-php-library .
我已经从https://github.com/mongodb/mongo-php-library下载了它。 I run the command
composer require "mongodb/mongodb=^1.0.0"
and what about the zip
file? 我运行命令
composer require "mongodb/mongodb=^1.0.0"
,而zip
文件又如何呢? Is there any easy method to install it? 有没有简单的安装方法?
I run this code 我运行这段代码
<?php
require 'vendor/autoload.php';
$connection = new MongoDB();
?>
and getting error: 并得到错误:
Fatal error: Class 'MongoDB' not found in C:\\wamp64\\www\\
致命错误:在C:\\ wamp64 \\ www \\中找不到类'MongoDB'
new MongoDB\Client("mongodb://localhost:27017");
works fine but for saving the document $collection->insert($document);
工作正常,但用于保存文档
$collection->insert($document);
gives the error insert method is not found
给出错误的
insert method is not found
If the files are in the vendor map the installation via composer went probably well. 如果文件在供应商地图中,则通过composer的安装可能进行得很好。 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: 从MongoDB的文档中:
$database = (new MongoDB\Client)->selectDatabase('db_name');
See the documentation on namespaces: http://php.net/manual/en/language.namespaces.php 请参阅有关名称空间的文档: http : //php.net/manual/zh/language.namespaces.php
-edit- -编辑-
For inserting you should use insertOne()
according to the documentation: http://mongodb.github.io/mongo-php-library/classes/collection/#insertone 对于插入,您应该根据文档使用
insertOne()
: http : insertOne()
function insertOne($document, array $options = []): MongoDB\InsertOneResult
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.