我试图创建新的mongo连接,执行以下代码
$m = new MongoDB\Client();
我得到了一个错误:
致命错误:找不到类'MongoDB\Client‘
我认为我已经正确地安装了MongoDB扩展(将php_mongodb.dll复制到ext文件夹,并使用extension=php_mongodb.dll更新了php.ini )。
以下代码确认它已加载:
echo extension_loaded("mongodb") ? "loaded\n" : "not loaded\n";我仍然收到同样的错误。
我很感激你的帮助。谢谢!
发布于 2016-12-08 05:47:06
如果使用的是PHP最新的MongoDB扩展,则MongoDB\Driver\Manager是扩展的主要入口点。
下面是使用最新扩展检索数据的示例代码。
假设您有testColl集合在testDb中。您可以使用扩展的MongoDB\Driver\Query类检索数据。
// Manager Class
$manager = new MongoDB\Driver\Manager("mongodb://localhost:27017");
// Query Class
$query = new MongoDB\Driver\Query(array('age' => 30));
// Output of the executeQuery will be object of MongoDB\Driver\Cursor class
$cursor = $manager->executeQuery('testDb.testColl', $query);
// Convert cursor to Array and print result
print_r($cursor->toArray());输出:
Array
(
[0] => stdClass Object
(
[_id] => MongoDB\BSON\ObjectID Object
(
[oid] => 5848f1394cea9483b430d5d2
)
[name] => XXXX
[age] => 30
)
)发布于 2018-02-28 07:15:42
我使用的是PHP7.1.9,我遇到了这个问题。通过删除和重新安装mongodb/mongodb来解决这个问题
composer remove mongodb/mongodb
composer require mongodb/mongodb另外,如果您正在使用Dreamweaver,请不要使用get将vendor文件夹放在服务器副本中。
安装之后,我现在可以使用MongoDB\Client了。
mongodb版本1.3,Mongodb扩展1.4
发布于 2016-12-05 10:09:35
在我身上也发生了同样的事情,请检查您服务器上的php安装版本。您必须使用PHPVersion5.6 .Check,即apche错误日志来获得更精确的错误细节。
https://stackoverflow.com/questions/40971613
复制相似问题