找不到类"MongoClient" [英] Class 'MongoClient' not found
问题描述
我正在尝试使此代码运行:
I'm trying to make this code run:
<?php
$m = new MongoClient("mongodb://54.72.237.242");
$db = $m->tilbud;
?>
每次我都遇到相同的错误:
Everytime I got the same error:
Fatal error: Class 'MongoClient' not found in C:\xampp\htdocs\conexion.php
我整天都在阅读有关此问题的信息,但是任何解决我问题的方法(我猜这是我做错的事情).
I've been reading about this problem the whole day but anything solves my issue (I guess it's something I'm doing wrong).
我下载了php_mongo.dll,将其复制到xampp/php/ext中,并在php.ini存档中添加了extension=php_mongo.dll
.
I downloaded the php_mongo.dll, I copied it in xampp/php/ext and I added extension=php_mongo.dll
in the php.ini archive.
我又添加了4个dll,因为我不确定必须使用哪个dll.
I've added 4 more dll's because I'm not sure which one I have to use:
-
extension=php_mongo-1.5.4-5.5-vc11-nts
-
extension=php_mongo-1.5.4-5.5-vc11
-
extension=php_mongo-1.5.4-5.5-vc11-nts-x86_64
-
extension=php_mongo-1.5.4-5.5-vc11-x86_64
extension=php_mongo-1.5.4-5.5-vc11-nts
extension=php_mongo-1.5.4-5.5-vc11
extension=php_mongo-1.5.4-5.5-vc11-nts-x86_64
extension=php_mongo-1.5.4-5.5-vc11-x86_64
因此,我现在收到5条警告,而不是一条.最后,我想其中一个会起作用,而我会删除其他四个.
So now im getting 5 warnings instead of one. At the end I guess one of them will work and I'll delete the other 4.
我尝试过的事情,我确定它们没问题:
Things I tried and I'm sure they are ok:
- extension_dir指向正确的文件夹.
- 我修改的php.ini文件是xammp加载的文件.
- Phpinfo没有显示任何有关mongo的信息.
我还能尝试什么?
修改
我尝试了
echo extension_loaded("mongo")吗? "loaded \ n":未加载\ n";
echo extension_loaded("mongo") ? "loaded\n" : "not loaded\n";
并且总是显示未加载".
and it always says 'not loaded'.
修改
最后!
问题是dll的名称.它必须是"php_mongo.dll",并且我正尝试加载全名dll,如我在本文开头提到的那样.因此,我为extension=php_mongo.dll
和voilà为我(extension=php_mongo-1.5.4-5.5-vc11
)更改了正确的dll!
Finally!
The problem was the dll's name. It has to be 'php_mongo.dll' and I was trying to load the full name dll as I said at the begining of this post. So I changed the correct dll for me (extension=php_mongo-1.5.4-5.5-vc11
) for extension=php_mongo.dll
and voilà!
推荐答案
You have not installed MongoDB PHP driver please see this link http://www.php.net/manual/en/mongo.installation.php
更新源
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10
echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen' | sudo tee /etc/apt/sources.list.d/mongodb.list
sudo apt-get update
安装MongoDB PHP驱动程序
Install MongoDB PHP Driver
sudo apt-get install php5-dev php5-cli php-pear -y
sudo pecl install mongo
打开您的php.ini文件并添加到其中:
Open your php.ini file and add to it:
extension=mongo.so
重新启动apache
Restart apache
sudo /etc/init.d/apache2 restart
其他帮助信息:
Other helping info:
这应该有助于找到您的php.ini文件:
this should help to find your php.ini file:
php -i | grep 'Configuration File'
在Ubuntu上显示以下内容:
On Ubuntu it shows this:
Configuration File (php.ini) Path => /etc/php5/cli
Loaded Configuration File => /etc/php5/cli/php.ini
请注意,您是从cli(命令行)运行此命令的,因此对于您真正的php.ini,请转到文件夹apache2而不是cli:)
take a note, that you run this command from cli (command line) so for your true php.ini go to folder apache2 instead of cli :)
这篇关于找不到类"MongoClient"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!