Emil Grigore
Emil Grigore

Reputation: 949

xampp mongoDB connection

I want to make a php app that uses Mongodb.
When I run the app on the localhost I get this:

Fatal error: Uncaught exception 'MongoConnectionException' with message 'Failed to connect to: 127.0.0.1:27017: Timed out after 1000 ms'

My code is:

<?php  
// Config  
$dbhost = 'localhost';  
$dbname = 'test';  

// Connect to test database  
$m = new Mongo("mongodb://$dbhost");  
$db = $m->$dbname;  

// select the collection  
$collection = $db->shows;  

// pull a cursor query  
$cursor = $collection->find();  
foreach($cursor as $document) {  
var_dump($document);  
}     
?>  

Upvotes: 0

Views: 1469

Answers (2)

Swaps
Swaps

Reputation: 1548

While installing the mongo-driver, also keep the "VC" version of your php installation.

Php extension version

And if you are counting the "MongoConnectionException", it seems that your php-mongo installation is fine. Also you are using "Mongo()" class for connection which is now deprecated; use "MongoClient" instead.

Thanks.. :)

Upvotes: 0

Martin Evans
Martin Evans

Reputation: 56

Enable it in your php.ini file and ensure your using the correct file in the extension directory.

Use phpinfo() to find if it is enabled.

If you still have trouble ensure that you are using the correct version of the Mongo driver.. http://docs.mongodb.org/ecosystem/drivers/php/

You will need to ensure your using the right version x86 or x64 and thread safe / non thread safe.

You will also be able to find that out from your phpinfo().

Upvotes: 1

Related Questions