title: PDO can I reuse the same Statement Handle for multiple queries?
body: <p>I am using PDO to access my data base and am looping using two while loops with fetch at the same time, seen below:</p>
  
  <pre><code>$DBH = new PDO('mysql:host=localhost;dbname=database;charset=utf8',$dblogin,$dbpass);
  $sql = 'SELECT * FROM table';
  $STH = $DBH-&gt;prepare($sql);
  $STH-&gt;execute();
  
  while ($bm_table = $STH-&gt;fetch(PDO::FETCH_ASSOC))
  {
      // SQL Query
      $sql1 = 'QUERY HERE';
      $STH1 = $DBH-&gt;prepare($sql1);
      $STH1-&gt;execute();
  
      // Loops through using different handle, but what if I used STH again?
      while ($row = $STH1-&gt;fetch(PDO::FETCH_ASSOC))
      {
          SomeFunction($bm_table,$row);
      }
  }
  </code></pre>
  
  <p>As you can see above I am using a different statement handle (<code>$STH</code>, <code>$STH1</code> etc.) Is this necessary? Or can I use just one statement handle for everything. The reason I have used multiple handles is as the <code>$bm_table</code> value that uses <code>$STH</code>, will still be in use while I am fetching <code>$row</code> wouldn't that change the value of <code>$bm_table</code> or stop the fetch from working? How does the handles with PDO work? Especially when in this case I have two simultaneous fetch loops running at the same time using the same PDO connection. </p>
  
  <p>So the main thing I am looking for here is if I have two statements that are running simultaneously is it important that I use different handles when I continue to use the same connection?</p>