title: PDO in my own PHP Class
body: <p>I'm newbie on PDO. I watch several videos. And i want to use my own database class as previous times. I want to use PDO instead of mysql* functions. I know that mysql* functions are deprecated in PHP 5.5</p>
  
  <p>I am not working on my old database class. Because it'll be more harder for a newbie. Now i only create a connection. And i want to select my products.</p>
  
  <p>Here is my code :</p>
  
  <pre><code>class Database extends PDO {
      private $_server         = "localhost";
      private $_user           = "root";
      private $_password       = "";
      private $_db             = "demo";
  
      private $_engine = 'mysql';
      private $link = NULL;
  
  
      public function __construct() {
          $dsn = $this-&gt;_engine.':dbname='.$this-&gt;_db.';host='.$this-&gt;_server.';charset=utf8';
  
          try {
              $this-&gt;link = new PDO($dsn, $this-&gt;_user, $this-&gt;_password);
              $this-&gt;link-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
          } catch (PDOException $e) {
              echo 'Connection failed: ' . $e-&gt;getMessage();
          }
      }
  }
  
  header('Content-Type: text/html; charset=utf-8');
  $DB = new Database();
  
  $sql = "SELECT * FROM product";
  $q  = $DB-&gt;query($sql);
  while($r = $q-&gt;fetch(Database::FETCH_ASSOC)){
      $products[] = $r;
  }
  
  echo "&lt;pre&gt;";
  print_r($products);
  echo "&lt;/pre&gt;";
  </code></pre>
  
  <p>I couldn't fetch my products. I'm recieving errors.</p>
  
  <blockquote>
    <p>Warning: PDO::query(): SQLSTATE[00000]: No error: PDO constructor was not called in /var/www/dt/includes/class/class.database.php on
    line 52</p>
    
    <p>Fatal error: Call to a member function fetch() on a non-object in
    /var/www/dt/includes/class/class.database.php on line 53</p>
  </blockquote>
  
  <p>What is my mistake ? And what should i do ?</p>