From Sagar Gulati, 5 Years ago, written in PHP.
Embed
  1. <?php
  2. class myprojMongoSingleton
  3. {
  4.     static $db = NULL;
  5.  
  6.     static function getMongoCon()
  7.     {
  8.         if (self::$db === null)
  9.         {
  10.             try {
  11.                 $m = new Mongo('mongodb://'.$MONGO['servers'][$i]['mongo_host'].':'.$MONGO['servers'][$i]['mongo_port']);
  12.  
  13.             } catch (MongoConnectionException $e) {
  14.                 die('Failed to connect to MongoDB '.$e->getMessage());
  15.             }
  16.             self::$db = $m;
  17.         }
  18.  
  19.         return self::$db;
  20.     }
  21. }
  22.  
  23. $m = myprojMongoSingleton::getMongoCon();
  24.  
  25. ?>

Replies to MongoDB Class Connect rss

Title Name Language When
Re: MongoDB Class Connect Guest php 4 Years ago.