title: PDO CLASS - Is this technically correct?
body: <p>I found the following PDO Class at <a href="http://culttt.com/2012/10/01/roll-your-own-pdo-php-class/" rel="nofollow">http://culttt.com/2012/10/01/roll-your-own-pdo-php-class/</a> by Philip Brown.</p>
  
  <p>I am new to Classes. This is working well. Does anyone see anything wrong with it or can it be improved? I want to use it in a large scale application.</p>
  
  <pre><code>class Database
  {
  private $host = DB_HOST;
  private $user = DB_USER;
  private $pass = DB_PASS;
  private $dbname = DB_NAME;
  
  private $dbh;
  private $error;
  
  private $stmt;
  
  public function __construct()
      {
      // Set DSN
      $dsn     = 'mysql:host=' . $this-&gt;host . ';dbname=' . $this-&gt;dbname;
      // Set options
      $options = array(
          PDO::ATTR_PERSISTENT =&gt; true,
          PDO::ATTR_ERRMODE =&gt; PDO::ERRMODE_EXCEPTION
      );
      // Create a new PDO instanace
      try
          {
          $this-&gt;dbh = new PDO($dsn, $this-&gt;user, $this-&gt;pass, $options);
          }
      // Catch any errors
      catch (PDOException $e)
          {
          $this-&gt;error = $e-&gt;getMessage();
          }
      }
  
  
  public function query($query)
      {
      $this-&gt;stmt = $this-&gt;dbh-&gt;prepare($query);
      }
  
  public function bind($param, $value, $type = null)
      {
      if (is_null($type))
          {
          switch (true)
          {
              case is_int($value):
                  $type = PDO::PARAM_INT;
                  break;
              case is_bool($value):
                  $type = PDO::PARAM_BOOL;
                  break;
              case is_null($value):
                  $type = PDO::PARAM_NULL;
                  break;
              default:
                  $type = PDO::PARAM_STR;
          }
          }
      $this-&gt;stmt-&gt;bindValue($param, $value, $type);
      }
  
  
  public function execute()
      {
      return $this-&gt;stmt-&gt;execute();
      }
  
  public function resultset()
      {
      $this-&gt;execute();
      return $this-&gt;stmt-&gt;fetchAll(PDO::FETCH_ASSOC);
      }
  
  public function single()
      {
      $this-&gt;execute();
      return $this-&gt;stmt-&gt;fetch(PDO::FETCH_ASSOC);
      }
  
  public function rowCount()
      {
      return $this-&gt;stmt-&gt;rowCount();
      }
  
  public function lastInsertId()
      {
      return $this-&gt;dbh-&gt;lastInsertId();
      }
  
  public function beginTransaction()
      {
      return $this-&gt;dbh-&gt;beginTransaction();
      }
  
  public function endTransaction()
      {
      return $this-&gt;dbh-&gt;commit();
      }
  
  public function cancelTransaction()
      {
      return $this-&gt;dbh-&gt;rollBack();
      }
  
  
  public function debugDumpParams()
      {
      return $this-&gt;stmt-&gt;debugDumpParams();
      }
  
  }
  </code></pre>