简体   繁体   English

未捕获的错误:找不到类“ MongoClient”

[英]Uncaught Error: Class 'MongoClient' not found

Trying to create a new Mongo connection using the following: $client = new Mongo(); 尝试使用以下命令创建新的Mongo连接: $client = new Mongo();

Sadly, this results in the following error: "Uncaught Error: Class 'Mongo' not found in". 可悲的是,这将导致以下错误:“未捕获的错误:未找到类'Mongo'。 I've also tried MongoClient, just in case this is the issue. 我也尝试过MongoClient,以防万一这是问题所在。

To make things more confusing, running phpinfo() in the same file results in the following. 为了使事情更加混乱,在同一文件中运行phpinfo()会导致以下结果。 在此处输入图片说明

Any help would be greatly appreciated. 任何帮助将不胜感激。

There are two PHP MongoDB packages, the Mongo extension and the newer MongoDB driver . 有两个PHP MongoDB软件包, 即Mongo扩展和较新的MongoDB驱动程序 You have the newer one, but you're writing code for the older one. 您有较新的代码,但您正在为较旧的代码编写代码。

Turns out that this is an issue in the official driver documentation. 原来,这是官方驱动程序文档中的问题。

You need to use new MongoDB\\Client and use the PHP library as well, rather than new MongoDB\\Driver\\Client as suggested. 您需要使用new MongoDB\\Client以及PHP库,而不是建议的new MongoDB\\Driver\\Client

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM