title: Why do I have an "Invalid argument supplied for foreach" in mysql connection?
body: <p>Here is my database connection </p>
  
  <pre><code> try {
          //create PDO connection 
          $db = new PDO("mysql:host=".DBHOST.";port=8889;dbname=".DBNAME, DBUSER, DBPASS);
          $db-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  
      } catch(PDOException $e) {
          //show error
          echo '&lt;p class="bg-danger"&gt;'.$e-&gt;getMessage().'&lt;/p&gt;';
          exit;
      }
  </code></pre>
  
  <p>I want select some values from my table:</p>
  
  <pre><code>$pdo = $db-&gt;prepare('SELECT  *  FROM animals ORDER BY id ASC;');
  foreach ($pdo-&gt;execute($db) as $row) {
      echo $row['name'];              
  }
  </code></pre>
  
  <p>But I get two warning messages:</p>
  
  <pre><code>Warning: PDOStatement::execute() expects parameter 1 to be array, object given in...
  </code></pre>
  
  <p>And the second warning:</p>
  
  <pre><code>Warning: Invalid argument supplied for foreach() in...
  </code></pre>
  
  <hr>
  
  <p>Edit, for JonStirling:</p>
  
  <pre><code> $pdo = $db-&gt;prepare('SELECT  *  FROM animals ORDER BY id ASC;');
   while ($row = $pdo-&gt;fetch())  {
          echo $row['name'];  
   }  
  </code></pre>
  
  <p>With this solution I do not get any warnings, but also still no results.</p>