'MongoDB \ Client'或'MongoDB \ Driver \ Manager(“ mongodb:// localhost:27017”)'均无效

时间:2018-10-05 01:57:06

标签: php mongodb mamp

我正在尝试使用MAMP安装用于PHP的mongoDB扩展,以便潜在地访问我的MongoDB服务器,据我所知,我所做的一切都正确,但是仍然出现错误。

我已经安装了MongoDB扩展-我可以知道是因为:

$sudo pecl install mongodb
pecl/mongodb is already installed and is the same as the released version 1.5.3
install failed

我的phpinfo也显示了这一点:

php mongodb extension

我还包括以下内容:

var_dump(extension_loaded('mongodb'));
echo phpversion('mongodb')."\n";

已返回:

/Applications/MAMP/htdocs/mongo.php:35:boolean true
1.5.3 

我也有:

$ 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告诉我我的php.ini文件在这里:

location of php ini file

我还添加了:

extension=mongodb.so

在我的PHP文件中,我具有以下内容:

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";

如果尝试使用MongDB / Client选项,则会出现以下错误:

Fatal error: Uncaught Error: Class 'MongoDB\Client' not found in /Applications/MAMP/htdocs/mongo.php on line 61

如果尝试使用MongoDB / Driver选项,则会出现以下错误:

Notice: Undefined property: MongoDB\Driver\Manager::$bob in /Applications/MAMP/htdocs/mongo.php on line 52

MongoDB \ Driver等的var_dump给出以下内容:

 /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

我有什么想念的吗?

1 个答案:

答案 0 :(得分:0)

您是否已将extension=mongodb.so添加到php.ini文件中?

这是我在此处未列出的唯一信息。