douchui1657 2018-08-13 22:26
浏览 390
已采纳

未找到“MongoDB \ Driver \ Manager”类(扩展未加载)

I'm aware that there are other questions similar to this one, but none of them have solutions to the exact problem that I'm having.

I've installed the mongodb php driver, added the dll to xampp/htdocs/ext, and editted php.ini to include the new extension. However, when I try to run this php:

<?php
$connection = new MongoDB\Driver\Manager("mongodb://localhost:27017");
$db = $connection->lotus;
$users = $db->users;
$document = array(
    "username"=>"firstuser",
    "password"=>"firstpass"
);
$users->insert($document);
?>

I get the error: Fatal error: Uncaught Error: Class 'MongoDB\Driver\Manager' not found in C:\xampp\htdocs\testproject\index.php:2 Stack trace: #0 {main} thrown in C:\xampp\htdocs\testproject\index.php on line 2

A post on this same issue says that they confirmed that the extension was loaded using the following code:

echo extension_loaded("mongo") ? "loaded
" : "not loaded
"

However, I always receive "not loaded" as the output. Not sure exactly what I'm doing wrong here. Any ideas?

EDIT

The current php version is 7.2.8. I also found this error message when I checked the php version: PHP Warning: PHP Startup: Unable to load dynamic library 'php_mongodb.dll' (tried: \xampp\php\ext\php_mongodb.dll (%1 is not a valid Win32 application.) This seems to be the source of the problem.

Solution has been found - see below

  • 写回答

1条回答 默认 最新

  • dream5694 2018-08-13 23:04
    关注

    Solution: I was using a 64-bit dll which was incompatible with the 32-bit xampp which was running php. Simply remove the 64-bit dll and download the 32-bit version.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 蓝牙耳机怎么查看日志
  • ¥15 Fluent齿轮搅油
  • ¥15 八爪鱼爬数据为什么自己停了
  • ¥15 交替优化波束形成和ris反射角使保密速率最大化
  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏