From Sagar Gulati, 5 Years ago, written in PHP.
Embed
  1. <?php
  2. /*!
  3.  * Environment & Function
  4.  * Version: 1.0 (08-12-2014)
  5.  * Last update: 03-1-2015
  6.  * Build with php 5.4.4
  7.  * Requires php v5.4.x or later
  8.  * Copyright (c) 2014 MindFreakers Networking
  9.  * Author: Sagar Gulati
  10.  * Email: sagar(at)mindfreakers(dot)net
  11.  * Dual licensed under the MIT and GPL licenses.
  12.  */
  13.  
  14. class GlobalTools
  15. {
  16.    
  17.     static $getcon = NULL;
  18.     static $getdb = NULL;
  19.     static $getcol = NULL;
  20.    
  21.     public function DoMongo($username, $password, $host, $port, $database, $col)
  22.     {
  23.         if (self::$getcon === null) {
  24.             try {
  25.                 $con     = new Mongo('mongodb://' . $username . ':' . $password . '@' . $host . ':' . $port);
  26.                 $db      = $con->selectDB($database);
  27.                 $collect = $db->$col;
  28.             }
  29.             catch (MongoConnectionException $e) {
  30.                 die('Failed to connect to MongoDB ' . $e->getMessage());
  31.             }
  32.             self::$getcon = $con;
  33.             self::$getdb  = $db;
  34.             self::$getcol = $collect;
  35.         }
  36.         return self::$getcol;
  37.     }
  38.    
  39.     public function DoMySQL($username, $password, $host, $port, $database)
  40.     {
  41.         $con = new PDO("mysql:host={$host}:{$port};dbname={$database}", "{$username}", "{$password}");
  42.         return $con;
  43.     }
  44.    
  45. }
  46.  
  47. ?>