title: I'm getting this error code: Invalid argument supplied for foreach()
body: <p>I am learning PDO and i am getting very confused, I have this piece of code below and all looks right to me however I'm getting this error code and I don't know what I have to do to fix it, please help me:</p>
  <pre><code>&lt;?php
  $hostname='localhost';
  $username='root';
  $password='';
  
  try {
      $dbh = new PDO(&quot;mysql:host=$hostname;dbname=stickercollections&quot;,$username,$password);
      echo 'Connected to Database&lt;br/&gt;';
      
      $sql = &quot;SELECT * FROM stickercollections&quot;;
  foreach ($dbh-&gt;query($sql) as $row)
      {
      echo $row[&quot;collection_brand&quot;] .&quot; - &quot;. $row[&quot;collection_year&quot;] .&quot;&lt;br/&gt;&quot;;
      }
      
      
      $dbh = null;
      }
  catch(PDOException $e)
      {
      echo $e-&gt;getMessage();
      }
  ?&gt; 
  </code></pre>
  <hr />
  <p><strong>Error Code</strong></p>
  <pre><code>Invalid argument supplied for foreach() in /Applications/XAMPP/xamppfiles/htdocs/GOTSWAPMAIN/index.php on line 11
  </code></pre>