title: Do I have this PDO Connection Class right?
body: <p>I've been playing around with PDO for the last few days, I'm working on a small CMS system to teach myself OOP skills, but even though it's only a small CMS, I want it to be able to handle whatever the web can throw at it.</p>
  
  <p>This is what I've come up with so far, I'm going to add connection pooling to the constructor to enable large amounts of concurrent connects on demand. I'm very new to this OOP stuff so I'm wanting a little advise and critism, no doubt I've done something terribly wrong here.</p>
  
  <p>I took the top answer to <a href="https://stackoverflow.com/questions/130878/global-or-singleton-for-database-connection">Global or Singleton for database connection?</a> as the base design, although I've added a private constructor as I want to use $this->dbConnectionInstance throughout the class for numerous helper functions to use.</p>
  
  <p>Thanks very much for your time, I really will appreciate any advise you can give me,</p>
  
  <p>-Drew</p>
  
  <pre><code>// Usage Example: $dbconn = dbManager::getConnection();
  //                $dbconn-&gt;query("SELECT * FROM accounts WHERE id=:id", "':id' =&gt; $id");
  
  &lt;?php
  
  class dbManager {
      private static $dbManagerInstance;
      private $dbConnectionInstance;
      private $stime;
      private $etime;
      public $timespent;
      public $numqueries;
      public $queries = array();
  
      public static function getManager(){
          if (!self::$dbManagerInstance){
              self::$dbManagerInstance = new dbManager();
          }
          return self::$dbManagerInstance;
      }
  
      // Server details stored in definition file
      private function __construct($db_server=DB_SERVER, $db_user=DB_USER, $db_pass=DB_PASS, $db_params=array(PDO::MYSQL_ATTR_INIT_COMMAND =&gt; "SET NAMES utf8")) {
          if(!$this-&gt;dbConnectionInstance)
          {
              try{
                  $this-&gt;dbConnectionInstance = new PDO($db_server, $db_user, $db_pass, $db_params);
                  $this-&gt;dbConnectionInstance-&gt;setAttribute(PDO::ATTR_PERSISTENT, PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
              } catch (PDOException $e) {
                  $this-&gt;dbConnectionInstance = null;
                  die($e-&gt;getMessage());
              }
          }
          return $this-&gt;dbConnectionInstance;
      }
  
      private function __destruct(){
          $this-&gt;dbConnectionInstance = null;
      }
  
      private function query($sql, $params = array()) {
          $this-&gt;queries[] = $sql;
          $this-&gt;numqueries++;
          $this-&gt;sTime = microtime();
          $stmt = $this-&gt;dbConnectionInstance-&gt;prepare($sql);
          $stmt-&gt;execute($params);
          $this-&gt;eTime = microtime();
          $this-&gt;timespent += round($this-&gt;eTime - $this-&gt;sTime, 4);
          return $stmt;
      }
  
  }
  
  ?&gt;
  </code></pre>
  
  <hr>
  
  <p>Thank you both for your suggestions, I've now added the rollback and commit into my exception handling, I'm just researching the use of buffered queries, I'm not entirely sure what ths will give me?</p>