title: Multiple Singleton mysql connections using same class
body: <p>I have a PHP app that uses 2 different databases. The connection is realized by a singleton mysql class. What I would like to achieve is to use the same class but to connect to another database depending on a variable stated when calling the class.
  So, the code used (but not yet functional):</p>
  
  <pre><code>/ start the single class
  class Singleton {
  
  // declare two private variables
  private static $_instace;
  private $conn;
  var $dbc = 0;
  
  // declare private constructor class
  private function __construct() {
      $this-&gt;conn = mysql_connect(HOST, USER, PASS);
      //die('DB State: [' . $this-&gt;dbc . ']');
      if ($this-&gt;dbc) {
         mysql_select_db(DB_DATABASE_PS);
      } else {
         mysql_select_db(DBNAME);
      }
  }
  
  // create a singleton method
  public static function getconnect($dbc = false) {
      if (!self::$_instace) {
          self::$_instace = new Singleton();   
          $_instace-&gt;dbc = $dbc;  
      } else {
          $_instace-&gt;dbc = $dbc;  
      }
      return self::$_instace;
  }
  }
  </code></pre>
  
  <p>When calling a class that uses the first database (DBNAME), it all works perfect but when trying to use the second database, the code doesn't help me at all.</p>
  
  <p>The code to load the second database inside a new class is made trough this code:</p>
  
  <pre><code>public function __construct() {
     $this-&gt;connect = Singleton::getconnect(true);
  }
  </code></pre>
  
  <p>Could someone help me figure it out?
  Thank you!</p>