Created
January 25, 2011 22:14
-
-
Save banker/795791 to your computer and use it in GitHub Desktop.
Sample PHP program using MongoDB and the official PHP driver.
This file contains hidden or 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(); | |
// select a database | |
$db = $m->training; | |
$coll = $db->messages; | |
for ($i = 0; $i < 10; $i = $i + 1) { | |
$coll->insert( array( "text" => "Hello World", "n" => $i ) ); | |
} | |
$cursor = $coll->find(); | |
foreach ($cursor as $obj) { | |
print $obj['_id'] . "\n"; | |
print print_r( $obj ) . "\n"; | |
} | |
print "\nCount " . $coll->count() . "\n"; | |
$coll->remove(); | |
print "\nCount " . print_r( $db->command( array( "count" => "messages" ) )) . "\n"; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment