未找到“MongoClient"类 [英] Class 'MongoClient' not found

查看:38
本文介绍了未找到“MongoClient"类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试运行此代码:

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:xampphtdocsconexion.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,因为我不确定我必须使用哪一个:

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

所以现在我收到了 5 个警告而不是一个.最后,我猜其中一个会起作用,我会删除其他 4 个.

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") ?"已加载 " : "未加载 ";

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

它总是说未加载".

编辑

终于!问题是dll的名称.它必须是php_mongo.dll",我试图加载全名 dll,正如我在本文开头所说的那样.所以我为 extension=php_mongo.dll 更改了正确的 dll(extension=php_mongo-1.5.4-5.5-vc11),瞧!

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à!

推荐答案

您还没有安装 MongoDB PHP 驱动请看这个链接 http://www.php.net/manual/en/mongo.installation.php

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

sudo /etc/init.d/apache2 restart

其他帮助信息:

这应该有助于找到您的 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆