Fatal Error - 'Mongo' class not found

2019-01-07 00:18发布

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.....


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

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

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\mongodb contents (therefore DBs are the exact same) and the exact same batch file to start mongod.exe as my Win7 Professional machine.

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.ini My Win7 Enterprise SP1 machine doesn't contain any reference to MongoDB.

The contents of the batch file I use to start 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

4条回答
来,给爷笑一个
2楼-- · 2019-01-07 00:48

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

I originally had been using the mongo-1.2.5-php5.3vc9ts version 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\db didn't exist/couldn't be found (and needed to be specified using --dbpath when running/starting mongod.exe).

查看更多
我欲成王,谁敢阻挡
3楼-- · 2019-01-07 00:49

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'

查看更多
\"骚年 ilove
4楼-- · 2019-01-07 00:50

If this problem exist in php CLI you should add extension=mongo.so to your /etc/php5/cli/php.ini file

查看更多
等我变得足够好
5楼-- · 2019-01-07 01:00

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.

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 )

Similar problem was caused by compiler issue;

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

查看更多
登录 后发表回答