Created
July 18, 2012 19:49
-
-
Save imjacobclark/3138427 to your computer and use it in GitHub Desktop.
MongoDB App for Connecting and Querying a DB
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 | |
class Controller { | |
protected $database; | |
public function __construct(Mongo $mongo = null, $database = 'teamomattic') { | |
if (null === $mongo) { | |
$mongo = new Mongo(); | |
} | |
$this->db = $mongo->selectDB($database)->users; | |
} | |
} | |
?> |
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 | |
require ('classes/mongo/controller.php'); | |
require ('classes/mongo/query.php'); | |
$mongo = new Controller; | |
$mongoQuery = new QueryMongo; | |
$connect = $mongoQuery->Database('username', 'Bioshox'); | |
?> |
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 | |
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