简体   繁体   English

MongoDb php扩展未加载

[英]MongoDb php extension not loading

I'm trying to load the MongoDb extension for php on a Windows 7 64 bit PC, running XAMPP with Apache 2.0 and PHP 5.3.5, compiler version VC6.我正在尝试在 Windows 7 64 位 PC 上加载用于 php 的 MongoDb 扩展,使用 Apache 2.0 和 PHP 5.3.5 运行 XAMPP,编译器版本 VC6。 I started out with this tutorial , and have also tried the extensions that the php documentation suggested.我从本教程开始,还尝试了php 文档建议的扩展。 MongoDb itself is running fine, and shell commands seem to work. MongoDb 本身运行良好,并且 shell 命令似乎可以工作。

At the moment I have:目前我有:

  1. Added extension=php_mongo.dll to my php.ini file. extension=php_mongo.dll添加到我的php.ini文件中。
  2. Put the VC6 version of php_mongo.dll (from the following download page , suggested by the PHP documentation) in the php/ext folder.php_mongo.dll的 VC6 版本(来自以下下载页面,由 PHP 文档建议)放在 php/ext 文件夹中。
  3. Restarted my Apache server.重新启动我的 Apache 服务器。

I have also tried php_mongo.dll files form Stealth's github , but they didn't seem to work either.我也尝试过Stealth 的 github中的php_mongo.dll文件,但它们似乎也不起作用。

When restarting Apache, I don't get any errors, but I can't find anything on MongoDb in phpinfo() , and the Mongo class is not recognised either.重新启动 Apache 时,我没有收到任何错误,但我在phpinfo()的 MongoDb 上找不到任何内容,并且 Mongo 类也无法识别。

Any ideas of what might be wrong?有什么想法可能是错的吗? Let me know if you need more info.如果您需要更多信息,请告诉我。

The problem might be incorrect version of extension.问题可能是不正确的扩展版本。 Try different versions downloaded from here: http://pecl.php.net/package/mongo/1.6.4/windows尝试从这里下载的不同版本: http : //pecl.php.net/package/mongo/1.6.4/windows

Use Bitnami WAMP Stack instead of XAMPP it comes preloaded php_mongo.dll driver installed and no need to configure php.ini file使用Bitnami WAMP Stack而不是 XAMPP 它预装了php_mongo.dll驱动程序,无需配置php.ini文件

There is no official MongoDB Driver released for PHP7.没有为 PHP7 发布官方 MongoDB 驱动程序。 So it would be better to download the recommended PHP version 5.5.30(currently) offered by Bitnami Wamp Stack.所以最好下载 Bitnami Wamp Stack 提供的推荐 PHP 版本 5.5.30(当前)。

There might be two reasons:可能有两个原因:

First one is as @Sadd suggested.第一个是@Sadd 建议的。 Your mongodb extension should be loaded after what you have done so its very likely that you have enabled extension in wrong file.您的 mongodb 扩展应该在您完成后加载,因此很可能您在错误的文件中启用了扩展。 And yes, there are two such similar files (named php.ini-development and php.ini-production on windows computers), so make sure to enable it in php.ini file and run the following code echo extension_loaded("mongodb") ? "loaded\\n" : "not loaded\\n";是的,有两个类似的文件(在 Windows 计算机上名为php.ini-developmentphp.ini-production ),因此请确保在php.ini文件中启用它并运行以下代码echo extension_loaded("mongodb") ? "loaded\\n" : "not loaded\\n"; echo extension_loaded("mongodb") ? "loaded\\n" : "not loaded\\n"; and you should see loaded on screen.您应该会在屏幕上看到已loaded

If you still don't see it, then the second thing you can do is to check whether the version is right or not.如果你还是没有看到,那么你可以做的第二件事就是检查版本是否正确。 You can check your phpinfo() for your php version and then put the right versioned dll file in ext folder.您可以检查phpinfo()的 php 版本,然后将正确版本的 dll 文件放在 ext 文件夹中。 In this, you can have to check whether your php is ts or nts and second one is whether your php is x64 or x86.在此,您必须检查您的 php 是 ts 还是 nts,第二个是您的 php 是 x64 还是 x86。 I hope you are good to go after one or both of the changes.我希望你能接受其中一项或两项更改。

This was driving my crazy until I looked closely at my PHP version:这让我发疯,直到我仔细查看我的 PHP 版本:

$ php -v
PHP 7.4.1 (cli) (built: Dec 17 2019 19:23:59) ( NTS Visual C++ 2017 x64 )

Notice that it says PHP 7.4.1 and NTS and x64 ?请注意,它说PHP 7.4.1 and NTS and x64 This means that when I download from PECL, I need version 7.4 Non Thread Safe (NTS) x64 or it won't run correctly.这意味着当我从 PECL 下载时,我需要7.4非线程安全 (NTS) x64 ,否则它将无法正确运行。

If the correct version of module is not added, an error is thrown.如果未添加正确版本的模块,则会引发错误。

[PHP Warning: PHP Startup: Unable to load dynamic library 'php_mongodb.dll' (tried: C:\xampp\php\ext\php_mongodb.dll (The specified module could not be found), C:\xampp\php\ext\php_php_mongodb.dll.dll (The specified module could not be found)) in Unknown on line 0] [PHP警告:PHP启动:无法加载动态库'php_mongodb.dll'(试过:C:\xampp\php\ext\php_mongodb.dll(找不到指定的模块),C:\xampp\php\ext \php_php_mongodb.dll.dll (The specified module could not be found)) in Unknown on line 0]

When downloading the dll extension from https://pecl.php.net/package/mongodb , make sure that NTS (Non Thread Safe) or TS (Thread Safe) is chosen according to what shown from php -v command.https://pecl.php.net/package/mongodb下载 dll 扩展时,请确保根据 php -v 命令显示的内容选择 NTS(非线程安全)或 TS(线程安全)。

$ php -v
PHP 8.1.7 (cli) (built: Jun  7 2022 21:45:53) (ZTS Visual C++ 2019 x64)

Although here it shows ZTS, TS version can be used in this case.虽然这里显示的是 ZTS,但在这种情况下可以使用 TS 版本。

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

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