title: PHP PDO fetchAll() returns empty array while SELECTing Temporary Table
body: <p>I'm having the following query, it contains a <code>Temporary Table</code>. If I use a <code>Temporary Table</code>, it returns an <strong><code>EMPTY ARRAY</code></strong>. If I removed the <code>Temporary Table</code> it returns an appropriate records.</p>
  
  <p>The following <code>SQL Query</code> contains a simple query, I just created a <code>Temporary Table</code> and inserted some records and I'm doing <code>SELECT</code> Query in that <code>Temporary Table</code>. I executed the same code in <strong>phpMyAdmin</strong>, it returns an appropriate records, but in <strong><code>PDO</code></strong> returns an <strong><code>EMPTY ARRAY</code></strong>.</p>
  
  <p>Sample and Simple SQL Query:</p>
  
  <p><strong>Case #1</strong>: <strong>With <code>Temporary Table</code></strong> - Returns an <strong><code>EMPTY ARRAY</code></strong></p>
  
  <pre><code>&lt;?php
  
  $query = &lt;&lt;&lt;SQL
  
  CREATE TEMPORARY TABLE TempContact (
      ContactId int, 
      FirstName varchar(30), 
      LastName varchar(30), 
      IsActiveContact Boolean
  );
  
  INSERT INTO TempContact (ContactId, FirstName, LastName, IsActiveContact)
  SELECT CT.ContactId, CT.FirstName, CT.LastName, 
      CASE WHEN SL.SalesId IS NOT NULL THEN TRUE ELSE FALSE END AS IsActiveContact
  FROM Contact CT
  LEFT JOIN Sales SL ON CT.ContactId = SL.ContactId;
  
  SELECT TC.* FROM TempContact TC;
  
  SQL;
  
  $stmt = $db-&gt;prepare($query);
  $result = $stmt-&gt;execute() ? $stmt-&gt;fetchAll() : null;
  
  ?&gt;
  </code></pre>
  
  <p><strong>Case #2</strong>: <strong>Without <code>Temporary Table</code></strong> - Returns an appropriate records</p>
  
  <pre><code>&lt;?php
  
  $query = &lt;&lt;&lt;SQL
  
  SELECT CT.ContactId, CT.FirstName, CT.LastName, 
      CASE WHEN SL.SalesId IS NOT NULL THEN TRUE ELSE FALSE END AS IsActiveContact
  FROM Contact CT
  LEFT JOIN Sales SL ON CT.ContactId = SL.ContactId;
  
  SQL;
  
  $stmt = $db-&gt;prepare($query);
  $result = $stmt-&gt;execute() ? $stmt-&gt;fetchAll() : null;
  
  ?&gt;
  </code></pre>
  
  <p>My actual code is so complex, due to easy understanding I added this simple query.</p>
  
  <p>I also checked for any error in my Query (Case #1 Query) using <code>print_r($stmt-&gt;errorInfo());</code>, but it returns an <code>EMPTY ARRAY</code> (<em>i.e., No Error in my Query</em>);. Moreover its not throwing any <code>PDOException</code>.</p>
  
  <p>Kindly assist me, how to get the records from the <code>Temporary Table SELECT</code></p>