Skip to content

Instantly share code, notes, and snippets.

@hndr91
Last active December 9, 2015 09:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hndr91/4530da2d369cc1af740d to your computer and use it in GitHub Desktop.
Save hndr91/4530da2d369cc1af740d to your computer and use it in GitHub Desktop.
slim mongo dbConnect
<?php
class dbConnect {
private $con;
private $db;
function __construct() {}
//connect to MongoDB function
function connect() {
include_once dirname(__FILE__) . '/config.php';
try {
//connect to Mongo with default setting
$this->con = new MongoClient();
//connect to database
$this->db = $this->con->selectDB(DB_NAME);
}
catch (MongoConnectionException $e) {
echo "Cannot Connect to MongoDB";
}
return $this->db;
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment