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?
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\
new MongoDB\Client("mongodb://localhost:27017");
works fine but for saving the document $collection->insert($document);
gives the error insert method is not found
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?
From the documentation of MongoDB:
$database = (new MongoDB\Client)->selectDatabase('db_name');
See the documentation on namespaces: http://php.net/manual/en/language.namespaces.php
-edit-
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