title: Call to a member function prepare() on a non-object? PDO?
body: <blockquote>
    <p>Fatal error: Call to a member function prepare() on a non-object in /.../public_html/deals/includes/deal.php on line 7</p>
  </blockquote>
  
  <p>I already created a database for deal and inserted all the tables with sample data. </p>
  
  <p>index.php (isnt finished yet)
          
  
  <pre><code>include_once('includes/connection.php');
  include_once('includes/deal.php');
  
  $deal = new Deal;
  $deals = $deal-&gt;fetch_all();
  
  ?&gt;
  
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
  &lt;title&gt;GameDeals&lt;/title&gt;
  &lt;link rel="stylesheet" href="assets/deals.css" /&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
  
  &lt;div class="container"&gt;
  &lt;!-- START GAMEDEALS --&gt;
  
  &lt;?php foreach ($deals as $deal) { ?&gt;
  
  &lt;div&gt;dsdsd&lt;?php echo $deal['deal_title']; ?&gt;&lt;/div&gt;
  &lt;?php } ?&gt;
  &lt;!-- END GAMEDEALS --&gt;
  &lt;/div&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>connection.php</p>
  
  <pre><code>&lt;?php 
  
  try {
      $pdo = new PDO('mysql:host=localhost;dbname=****', $**username**, $**pwd**);
      } 
  
  catch (PDOException $e)
      {
          return "Database connection error.";
      }
  
  ?&gt;
  </code></pre>
  
  <p>deal.php</p>
  
  <pre><code>&lt;?php
  
  class Deal {
      public function fetch_all() {
          global $pdo;
  
          $query = $pdo-&gt;prepare("SELECT * FROM deals");
          $query-&gt;execute();
  
          return $query-&gt;fetchAll();
      }
  }
  
  ?&gt;
  </code></pre>
  
  <p>Any ideas? </p>
  
  <pre><code>    &lt;?php
  
  class Deal {
      public function fetch_all() {
          global $pdo;
  
          var_dump($pdo);
          $query = $pdo-&gt;prepare("SELECT * FROM deals");
          $query-&gt;execute();
  
          return $query-&gt;fetchAll();
      }
  }
  
  ?&gt;
  </code></pre>
  
  <p>Result: </p>
  
  <blockquote>
    <p>NULL 
    Fatal error: Call to a member function prepare() on a non-object in /.../public_html/deals/includes/deal.php on line 8</p>
  </blockquote>