Skip to content

Instantly share code, notes, and snippets.

@jvoorhis
Forked from lhitchon/gist:1424751
Created December 3, 2011 23:15
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jvoorhis/1428465 to your computer and use it in GitHub Desktop.
Save jvoorhis/1428465 to your computer and use it in GitHub Desktop.
PHP MongoLab sample
<html>
<head>
<title>Demo</title>
</head>
<body>
<h1>PHP Mongo Test</h1>
<?php
try {
$connect = $_ENV["MONGOLAB_URI"];
$m = new Mongo($connect);
$db = $m->selectDB($db);
echo "<h2>Collections</h2><ul>";
$cursor = $db->listCollections();
$collection_name = "";
foreach( $cursor as $doc ) {
echo "<li>" . $doc->getName() . "</li>";
$collection_name = $doc->getName();
}
echo "</ul>";
if ( $collection_name != "" ) {
$collection = $db->selectCollection($collection_name);
echo "<h2>Documents in ${collection_name}</h2>";
$cursor = $collection->find();
foreach( $cursor as $doc ) {
echo "<pre>";
var_dump($doc);
echo "</pre>";
}
}
} catch ( Exception $e ) {
echo "Exception: ", $e->getMessage(), "\n";
}
?>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment