Skip to content

Instantly share code, notes, and snippets.

@imjacobclark
Created July 18, 2012 19:49
Show Gist options
  • Save imjacobclark/3138427 to your computer and use it in GitHub Desktop.
Save imjacobclark/3138427 to your computer and use it in GitHub Desktop.
MongoDB App for Connecting and Querying a DB
<?php
class Controller {
protected $database;
public function __construct(Mongo $mongo = null, $database = 'teamomattic') {
if (null === $mongo) {
$mongo = new Mongo();
}
$this->db = $mongo->selectDB($database)->users;
}
}
?>
<?php
require ('classes/mongo/controller.php');
require ('classes/mongo/query.php');
$mongo = new Controller;
$mongoQuery = new QueryMongo;
$connect = $mongoQuery->Database('username', 'Bioshox');
?>
<?php
class QueryMongo extends Controller{
function Database($property, $find){
$rangeQuery = array($property => $find);
$cursor = $this->db->find($rangeQuery);
foreach ($cursor as $doc){
echo $doc[''.$property.''];
}
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment