Like mentioned in my previous blog about MongoDB, i changed the backend database in some websites, from MySQL to MongoDB.

Migrated a simple PHP – MySQL website to PHP – MongoDB

When i moved my server into the Cloud ( Thanks to Prominic.NET), i decided to upgrade to MongoDB to version 3.4, not realizing that this would be a great difference for my code.

The class MongoClient no longer exists. So i changed my code to the new class MongoDB\Driver\*

Here are the differences in my code:

Old Code
$manager = new MongoClient('mongodb://localhost/datesangioni');
$collection = $db->maanden;
$cursor = $collection->find();
foreach ($cursor as $document) {
$maand[$document['maand']]=$document['omschrijving'];
}

 

New Code
$manager = new MongoDB\Driver\Manager("mongodb://localhost:27017");
$query = new MongoDB\Driver\Query([]); 
$cursor = $manager->executeQuery('datesangioni.maanden', $query);
foreach ($cursor as $document) { 
$maand[$document->maand] = $document->omschrijving; 
}

 

Working all perfectly again !!

 

Visits: 285

By angioni

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.