php 致命错误 - 找不到“Mongo”类

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8927255/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 05:47:54  来源:igfitidea点击:

Fatal Error - 'Mongo' class not found

phpapachemongodbinstallationwamp

提问by Adam Lynch

I'm trying to execute this:

我正在尝试执行此操作:

<?php

// connect
$m = new Mongo();

?>

But I get the following error:

但我收到以下错误:

Fatal error: Class 'Mongo' not found in C:\wamp\www.....

致命错误:在 C:\wamp\www 中找不到“Mongo”类.....



Info:

信息:

  • PHP: 5.38
  • MongoDB: mongodb-win32-i386-2.0.2
  • MongoDB PHP Driver: mongo-1.1.4-php5.3vc6ts
  • WampServer: 2.2
  • OS: Windows 7 Enterprise SP1
  • PHP:5.38
  • MongoDB:mongodb-win32-i386-2.0.2
  • MongoDB PHP 驱动程序:mongo-1.1.4-php5.3vc6ts
  • WampServer:2.2
  • 操作系统:Windows 7 Enterprise SP1

I've followed the MongoDB installation fine (incl. adding the DLL to ext & php.ini), I've started mongod.exe and WAMP is running.

我已经很好地遵循了 MongoDB 安装(包括将 DLL 添加到 ext 和 php.ini),我已经启动了 mongod.exe 并且 WAMP 正在运行。

What does this imply is missing/incorrect?

这意味着什么是缺失/不正确的?



Edit:

编辑:

I have got it running on another Windows 7 machine (Windows 7 Profressional). That got me curious. So now my Windows 7 Enterprise SP1 machine has the same http.conf, php.ini, C:\wamp\bin\mongodbcontents (therefore DBs are the exact same) and the exact same batch file to start mongod.exeas my Win7 Professional machine.

我让它在另一台 Windows 7 机器上运行(Windows 7 Professional)。这让我很好奇。所以现在我的 Windows 7 Enterprise SP1 机器具有相同的http.conf, php.ini,C:\wamp\bin\mongodb内容(因此数据库完全相同)和完全相同的批处理文件,以mongod.exe与我的 Win7 Professional 机器启动。

But still, all I can do on my Win7 Enterprise SP1 machine is connect via command line. My Win7 Professional machine's phpinfo()contains:
Mongo section in php.iniMy Win7 Enterprise SP1 machine doesn't contain any reference to MongoDB.

但是,我在 Win7 Enterprise SP1 机器上所能做的就是通过命令行连接。我的 Win7 Professional 机器phpinfo()包含:
php.ini 中的 Mongo 部分我的 Win7 Enterprise SP1 机器不包含对 MongoDB 的任何引用。

The contents of the batch file I use to start MongoDB:

我用来启动 MongoDB 的批处理文件的内容:

"C:\wamp\bin\mongodb\bin\mongod.exe" --logpath "C:\wamp\bin\mongodb\logs\error.log" --logappend --dbpath "C:\wamp\bin\mongodb\data\db" --directoryperdb --service
Net Start "MongoDB"
pause

采纳答案by Adam Lynch

The problem was the PHP driver (php_mongo.dll). Apache/WAMP just did not like the mongo-1.1.4-php5.3vc6tsversion for some reason. My Windows 7 Professional machine had the mongo-1.2.5-php5.3vc9tsversion. That was the only difference between the two machines.

问题出在 PHP 驱动程序 ( php_mongo.dll) 上。mongo-1.1.4-php5.3vc6ts出于某种原因,Apache/WAMP 只是不喜欢该版本。我的 Windows 7 Professional 机器有这个mongo-1.2.5-php5.3vc9ts版本。这是两台机器之间的唯一区别。

I originally had been using the mongo-1.2.5-php5.3vc9tsversion of the driver on the Windows 7 Enterprise machine but changed to the mongo-1.1.4-php5.3vc6tsversion when I was troubleshooting the problem. So the original problem could actually just have been that the database path data\dbdidn't exist/couldn't be found (and needed to be specified using --dbpathwhen running/starting mongod.exe).

我原来一直在使用mongo-1.2.5-php5.3vc9tsWindows 7 Enterprise 机器上的驱动程序版本,但mongo-1.1.4-php5.3vc6ts在我对问题进行故障排除时更改为该版本。因此,最初的问题实际上可能只是数据库路径data\db不存在/无法找到(并且需要--dbpath在运行/启动时使用指定mongod.exe)。

回答by Sina Miandashti

If this problem exist in php CLI you should add extension=mongo.soto your /etc/php5/cli/php.inifile

如果这个问题存在于 php CLI 中,你应该添加extension=mongo.so到你的/etc/php5/cli/php.ini文件中

回答by cwhisperer

On Ubuntu, I used this tutorial. Once installed, echo the phpinfo() and check if the mongo.ini file is located in the correct directory mentioned in phpinfo with 'Scan this dir for additional .ini files'

在 Ubuntu 上,我使用了本教程。安装后,回显 phpinfo() 并检查 mongo.ini 文件是否位于 phpinfo 中提到的正确目录中,并使用“扫描此目录以获取其他 .ini 文件”

回答by lqez

Check out the exact compiler name of your PHP binary in phpinfo page and try to reinstall the mongo driver was built on same compiler.

在 phpinfo 页面中查看 PHP 二进制文件的确切编译器名称,并尝试重新安装基于相同编译器构建的 mongo 驱动程序。

http://www.php.net/manual/en/mongo.installation.php#mongo.installation.windows

http://www.php.net/manual/en/mongo.installation.php#mongo.installation.windows

You're using the mongo driver was bulit on Visual Studio 6 with Thread-safe, now. ( vs6ts means it )

您现在使用的 mongo 驱动程序是在具有线程安全的 Visual Studio 6 上构建的。( vs6ts 意味着它)

Similar problem was caused by compiler issue;

类似的问题是由编译器问题引起的;

http://www.php.net/manual/en/mongo.installation.php#104223

http://www.php.net/manual/en/mongo.installation.php#104223