Created
December 1, 2011 22:50
-
-
Save skierkowski/1420473 to your computer and use it in GitHub Desktop.
MongoDB PHP Fog Example
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 | |
// connect | |
$m = new Mongo($_ENV["MONGOLAB_URI"]); | |
// select a database | |
$db = $m->comedy; | |
// select a collection (analogous to a relational database's table) | |
$collection = $db->cartoons; | |
// add a record | |
$obj = array( "title" => "Calvin and Hobbes", "author" => "Bill Watterson" ); | |
$collection->insert($obj); | |
// add another record, with a different "shape" | |
$obj = array( "title" => "XKCD", "online" => true ); | |
$collection->insert($obj); | |
// find everything in the collection | |
$cursor = $collection->find(); | |
// iterate through the results | |
foreach ($cursor as $obj) { | |
echo $obj["title"] . "\n"; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment