title: Connection with multiple users using singleton pattern pdo connection
body: <ol>
  <li>I have a database with 5 users like hr, pay ,misc. I am using singleton database pattern to connect and execute query to these database users.</li>
  <li>I am accessing connection information from Config Class, where i am storing connection parameters as an array.</li>
  <li><p>I want to get a new connection object when i change parameter in getInstance method for example 
   $data1 = DB::getInsatance('common')->query("select * from Table1 (in common)"); 
   $data2 = DB::getInsatance('misc')->query("select * from Table2 (in misc) ");</p>
  
  <p>But whenever two instance methods are created with seperate users,the object initiated later in the flow is not generated    </p></li>
  </ol>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;!--
  This is my DB class where my pdo parameters will change based on arguement supplied in getInstance() method  ---&gt;
  
  
  
  
  &lt;?php
  include_once 'Config.php';
  class DB {
   private static $_instance = null;
   private $_pdo, $_query, $_error = false, $_results, $_count = 0;
   protected $user;
   private function __construct($user) {
   try {
     $this -&gt; _pdo = new PDO('oci:dbname=//' . Config::get($user.'/host') . '/' . Config::get($user.'/db'), Config::get($user.'/username'), Config::get($user.'/password'));
  
    } catch (PDOException $e) {
     die($e -&gt; getMessage());
    }
    
    
   }
  
   public static function getInstance($user) {
    
    if (!isset(self::$_instance)) {
     self::$_instance = new DB($user);
    }
    //return $user;
    return self::$_instance;
   }
  
   public function query($sql, $params = array()) {
    //echo $sql.'&lt;br&gt;';
    $this -&gt; _error = false;
    if ($this -&gt; _query = $this -&gt; _pdo -&gt; prepare($sql)) {
     $x = 1;
     if (count($params)) {
      foreach ($params as $param) {
       $this -&gt; _query -&gt; bindValue($x, $param);
       $x++;
      }
     }
  
     if ($this -&gt; _query -&gt; execute()) {
      $this -&gt; _results = $this -&gt; _query -&gt; fetchAll(PDO::FETCH_OBJ);
      foreach ($this -&gt;_results as $result) {
       $this -&gt; _count++;
  
      }
      //return $this -&gt;_count;
     } else {
      $this -&gt; _error = true;
     }
    }
    return $this;
   }
  
   public function action($action, $table, $where = array()) {
    if (count($where) === 3) {
     $operators = array('=', '&gt;', '&lt;', '&gt;=', '&lt;=','like');
  
     $field = $where[0];
     $operator = $where[1];
     $value = $where[2];
  
     if (in_array($operator, $operators)) {
      $sql = "{$action} FROM {$table} WHERE {$field} {$operator} ?";
  
      if (!$this -&gt; query($sql, array($value)) -&gt; error()) {
       return $this;
      }
     }
    }
    return false;
   }
  
   public function get($table, $where) {
    return $this -&gt; action('SELECT *', $table, $where);
   }
  
   public function delete($table, $where) {
    return $this -&gt; action('DELETE', $table, $where);
   }
  
   public function getf($keys = array(), $table, $wheres = array(array(),array(),array())) {
  
    $fields = $wheres[0];
    $qoperator = $wheres[1];
    $values = $wheres[2];
    $operators = array('=', '&gt;', '&lt;', '&gt;=', '&lt;=');
    foreach ($fields as $field) {
     $this -&gt; field = $field;
    }
    foreach ($qoperator as $operator1) {
     $this -&gt; operator = $operator1;
  
    }
    foreach ($values as $value1) {
     $this -&gt; value = $value1;
  
    }
  
    //if (in_array($operator, $operators)) {
    if (count($fields) === count($values)) {
     $sql = "SELECT " . implode(',', $keys) . "FROM {$table} WHERE" . implode('AND', '{$field} {$operator} ?');
  
    } elseif (count($fields) === 0) {
     $sql = "SELECT " . implode(',', $keys) . "FROM {$table} WHERE" . implode('AND', '{$field} {$operator} ?');
  
    }
    if (!$this -&gt; query($sql, array($value)) -&gt; error()) {
     return $this;
    }
  
    //}
  
    return false;
   }
  
   public function select($keys, $table, $where) {
  
    return $this -&gt; getf($keys, $table, $where);
   }
  
   public function insert($table, $fields = array()) {
    $keys = array_keys($fields);
    $values = '';
    $x = 1;
    foreach ($fields as $field) {
     $values .= '?';
     if ($x &lt; count($fields)) {
      $values .= ', ';
     }
     $x++;
    }
  
    $sql = "INSERT INTO {$table} (" . implode(',', $keys) . ") VALUES ({$values})";
    if (!$this -&gt; query($sql, $fields) -&gt; error()) {
     return true;
  
    }
    return false;
   }
  
   public function update($table, $id, $fields) {
    $set = '';
    $x = 1;
  
    foreach ($fields as $name =&gt; $value) {
     $set .= "{$name} = ?";
     if ($x &lt; count($fields)) {
      $set .= ', ';
     }
     $x++;
    }
    $sql = "UPDATE {$table} SET {$set} WHERE TENDER_ID = {$id}";
    
    if (!$this -&gt; query($sql, $fields) -&gt; error()) {
     return true;
    }
    return false;
   }
  
   public function results() {
    return $this -&gt; _results;
   }
  
   public function first() {
    //return $this-&gt;results()[0];
    return current($this -&gt; results());
   }
  
   public function error() {
    return $this -&gt; _error;
   }
  
   public function count() {
    return $this -&gt; _count;
   }
  
  }
  ?&gt;</code></pre>
  </div>
  </div>
  </p>