Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
392 views
in Technique[技术] by (71.8m points)

php - 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: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).

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.

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

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:

  • The extension_dir is pointing to the correct folder.
  • The php.ini that I modified is the one that xammp loads.
  • Phpinfo dosen't show anything about mongo.

What more can I try ?

Edit

I tried

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

and it always says 'not loaded'.

Edit

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You have not installed MongoDB PHP driver please see this link http://www.php.net/manual/en/mongo.installation.php

Update sources

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

Install MongoDB PHP Driver

sudo apt-get install php5-dev php5-cli php-pear -y
sudo pecl install mongo

Open your php.ini file and add to it:

extension=mongo.so

Restart apache

sudo /etc/init.d/apache2 restart

Other helping info:

this should help to find your php.ini file:

php -i | grep 'Configuration File'

On Ubuntu it shows this:

Configuration File (php.ini) Path => /etc/php5/cli
Loaded Configuration File => /etc/php5/cli/php.ini

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 :)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...