Created
          September 13, 2012 18:37 
        
      - 
      
- 
        Save jimmysawczuk/3716558 to your computer and use it in GitHub Desktop. 
  
    
      This file contains hidden or 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 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