Created
November 23, 2016 20:31
-
-
Save bjpeterdelacruz/0c4dc6f143402f79616956158964d930 to your computer and use it in GitHub Desktop.
Retrieving all documents from MongoDB database (PHP 5 vs. PHP 7)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// PHP 5 | |
$m = new MongoClient(); | |
$db = $m->test; | |
$collection = $db->todos; | |
$cursor = $collection->find(); | |
foreach ($cursor as $document) { | |
echo $document["name"] . "\n"; | |
} | |
// PHP 7 | |
$m = new MongoDB\Driver\Manager(); | |
$query = new MongoDB\Driver\Query([]); | |
$collection = $m->executeQuery("test.todos", $query); | |
foreach($collection as $document) { | |
echo $document->name . "\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment