I am trying to install the mongoDB extension for PHP with MAMP so I can potentially access my MongoDB server, and as far as I can tell, I have done everything right, yet I am still getting errors.
I have the MongoDB extension installed - I can tell because:
$sudo pecl install mongodb
pecl/mongodb is already installed and is the same as the released version 1.5.3
install failed
Also my phpinfo shows this:
Also I have included the following:
var_dump(extension_loaded('mongodb'));
echo phpversion('mongodb')."\n";
which have returned:
/Applications/MAMP/htdocs/mongo.php:35:boolean true
1.5.3
I also have:
$ composer require mongodb/mongodb
Using version ^1.4 for mongodb/mongodb
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Nothing to install or update
Generating autoload files
phpinfo tells me my php.ini file is here:
And i have added to that:
extension=mongodb.so
In my PHP file I have the following:
require 'vendor/autoload.php'; // include Composer's autoloader
$m = new MongoDB\Driver\Manager("mongodb://localhost:27017");
//$m = new MongoDB\Client("mongodb://localhost:27017");
echo "connected successfully";
// select a database
$db = $m->bob;
echo "database selected";
If I try the MongDB/Client option, I get the following error:
Fatal error: Uncaught Error: Class 'MongoDB\Client' not found in /Applications/MAMP/htdocs/mongo.php on line 61
If I try the MongoDB/Driver option, I get the following error:
Notice: Undefined property: MongoDB\Driver\Manager::$bob in /Applications/MAMP/htdocs/mongo.php on line 52
A var_dump of MongoDB\Driver etc. gives the following:
/Applications/MAMP/htdocs/mongo.php:38:
object(MongoDB\Driver\Manager)[3]
public 'uri' => string 'mongodb://localhost:27017' (length=25)
public 'cluster' =>
array (size=0)
empty
Is there anything I could be missing?