简体   繁体   English

PHP的:找不到Mongo类

[英]PHP : Mongo class not found

I am trying to run MongoDB with PHP. 我试图用PHP运行MongoDB。 I have XAMPP 1.7.7 installed on my machine (Windows XP - 32 bit). 我的机器上安装了XAMPP 1.7.7(Windows XP-32位)。

The PHP version is 5.3.8 and Apache version is 2.2.21. PHP版本是5.3.8,Apache版本是2.2.21。 I installed the PHP MongoDB drivers as was given on their instructions page. 我按照说明页面中的说明安装了PHP MongoDB驱动程序。 I have the php_mongo.dll from this zip - mongo-1.1.4-php5.3vc9ts ( because i see that Thread Safety is enabled). 我从此zip中获取了php_mongo.dll-mongo-1.1.4-php5.3vc9ts(因为我看到启用了线程安全性)。

However, i always keep getting the message - 'Fatal error: Class 'Mongo' not found' for this code snippet- 但是,我始终会收到此代码段的消息-'致命错误:未找到类'Mongo'-

$mongo = new Mongo();
$db = $mongo->database_name;

Does anyone know the solution to this ? 有人知道解决方案吗?

Thanks in advance. 提前致谢。

Please see this link - Error installing MongoDb PHP driver with XAMPP on Max OS Lion - I think it's possibly the same issue, though it was on Mac OS whereas you're on Windows. 请查看此链接- 在Max OS Lion上用XAMPP安装MongoDb PHP驱动程序时出错 -我认为这可能是相同的问题,尽管它在Mac OS上却在Windows上。

I believe that you may need to install the xampp "Developer Package", required to build additional php extension. 我相信您可能需要安装xampp“开发人员软件包”,以构建其他php扩展。

The "Developer Package" can be found here : http://www.apachefriends.org/en/xampp-windows.html . 可以在以下位置找到“开发人员软件包”: http : //www.apachefriends.org/en/xampp-windows.html

Problem solved !! 问题解决了 !! What i did was re-installed Apache and applied the changes. 我所做的是重新安装了Apache并应用了更改。 It worked, although i don't know what went wrong in the first place !! 它起作用了,尽管我一开始不知道出了什么问题! Thank you everyone for your help !! 谢谢你们每一个人的帮助 !!

It's because you forgive something .. Mongo don't understand a class unknow so you have to do that : 这是因为您原谅了某件事.. Mongo不了解班级未知,所以您必须这样做:

$mongo = new MongoClient();
$db = $mongo->database_name;

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

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