Skip to content

Instantly share code, notes, and snippets.

@jimmysawczuk
Created September 13, 2012 18:37
Show Gist options
  • Save jimmysawczuk/3716558 to your computer and use it in GitHub Desktop.
Save jimmysawczuk/3716558 to your computer and use it in GitHub Desktop.
<?php
class MongoHelper
{
private static $servers = array();
public static function addServer($name, $host, $port = 27017)
{
self::$servers[$name] = "mongodb://{$host}:{$port}";
}
public static function load($name, $db = false)
{
if (isset(self::$servers[$name]))
{
if ($db === false)
{
return new Mongo(self::$servers[$name]);
}
else
{
$m = new Mongo(self::$servers[$name]);
return $m->$db;
}
}
else
{
throw new Exception("Mongo server {$name} not found!");
return false;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment