title: Including PDO database connection in class
body: <p>I have been trying to figure out the best way to include my PDO database connection in my classes. Here is the code i have so far and won't work.</p>
  
  <pre><code>class Delete {
  
  private $connection;
      function __construct() {
          $this-&gt;open_connection();
      }
      public function open_connection() {
          $this-&gt;connection = mysql_connect(localhost, 1, 1);
          if (!$this-&gt;connection) {
              die("Database connection failed: " . mysql_error());
          } else {
              $db_select = mysql_select_db(1, $this-&gt;connection);
              if (!$db_select) {
                  die("Database selection failed: " . mysql_error());
              }
          }
      }
  
  public function delete_file($deletelink) {
  
  $dbh = $this-&gt;connection;
  
  
  
  $sth = $dbh-&gt;prepare("SELECT hash FROM files WHERE delete_link = :delete_link");
  //PARAM_INT for int, PARAM_STR for string, PARAM_BOOL for bool
  $sth-&gt;bindParam(':delete_link', $deletedlink, PDO::PARAM_STR);
  $sth-&gt;execute();
  $countrows = $sth-&gt;rowCount();
   if ($countrows == 0) {
  return false;   
   } else {
  
  
  
  $sth = $dbh-&gt;prepare("SELECT filename, hash, ext FROM files WHERE delete_link = :delete_link");
  //PARAM_INT for int, PARAM_STR for string, PARAM_BOOL for bool
  $sth-&gt;bindParam(':delete_link', $deletedlink, PDO::PARAM_STR);
  $sth-&gt;execute();
  
  }
  </code></pre>
  
  <p>}</p>
  
  <p>If anyone has a better way of doing it, please share =) Thanks guys!</p>