title: Returning multiple SELECT queries in single array
body: <p>I am writing angularjs application that relies on data returned from MySQL database.</p>
  
  <p>Angularjs code makes a HTTP request and logs the returned data to the console:</p>
  
  <pre><code>$http({method: 'POST', url: 'php/return_something.php', headers: {'Content-Type': 'application/json'}})
      .success(function(data, status, headers, config) {
      //The API call to the back-end was successful (i.e. a valid session)
          console.log(data);
      })
      .error(function(data, status, headers, config) {
          console.log("Error.");
      });
  </code></pre>
  
  <p><em>return_something.php</em></p>
  
  <pre><code>try
  {
      $conn = new PDO("mysql:host=".DB_HOST."; dbname=".DB_DATABASE, DB_USER, DB_PASSWORD);
      // set the PDO error mode to exception
      $conn-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
      $sql = $conn-&gt;prepare("SELECT count(id_table_x) from table_x; SELECT count(id_table_y) from table_y;");
      $sql-&gt;execute();
  
      // set the resulting array to associative
      $results = $sql-&gt;fetchAll(PDO::FETCH_ASSOC);
      echo json_encode($results);
  }
  
  catch(PDOException $e)
  {
      echo $sql . "&lt;br /&gt;" . $e-&gt;getMessage();
  }
  
  $conn = null;
  </code></pre>
  
  <p>To the console an array with one element gets logged.</p>
  
  <blockquote>
    <p>[Object]</p>
  </blockquote>
  
  <p>Inside this object there is a result of the first query (<em>"SELECT count(id_table_x) from table_x"</em>).</p>
  
  <p>What should I change that I would see the result of the second query (<em>"SELECT count(id_table_y) from table_y"</em>) as the second element of this array? Any help appreciated.</p>