title: PHP PDO sqlsrv executing multiple SELECT COUNT
body: <p>I'm at the very beginning of my PDO learning curve and soaking up all I can learn. Please can you advise if the code below is the best approach.  I want to find if a user has an entry in more than one SQL Server table</p>
  
  <pre><code>try {
      $conn = new PDO("sqlsrv:Server=$pdoServer;Database=$pdoDatabase;", $pdoUID, $pdoPWD);
      $conn-&gt;setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING );  
  } catch (PDOException $e) {
      die(error_log(print_r("Could not connect to SQL Server".$e-&gt;getMessage(), TRUE), 0));
  }
  
  if (isValidUsername($username)) {
      $res_sites = $res_PR = $res_TA = array();
  
      try {
          $stmt_PR = $conn-&gt;prepare("SELECT Count(*) AS PRcounter FROM tbl1 WHERE usr_username=:username");
          $stmt_TA = $conn-&gt;prepare("SELECT Count(*) AS TAcounter FROM tbl2 WHERE usr_username=:username");
  
          $stmt_PR-&gt;bindParam(':username',$username,PDO::PARAM_STR);
          $stmt_TA-&gt;bindParam(':username',$username,PDO::PARAM_STR);
  
          $stmt_PR-&gt;execute();
          $stmt_TA-&gt;execute();
  
          $res_PR = $stmt_PR-&gt;fetch();
          $res_TA = $stmt_TA-&gt;fetch();
  
          $stmt_sites = $conn2-&gt;query("SELECT site_ID,site_name FROM tbl3 WHERE isDeleted IS NULL ORDER BY site_name ASC");
          while ($row = $stmt_sites-&gt;fetch(PDO::FETCH_ASSOC)){
              $res_sites[$row['site_ID']]['site_name']=$row['site_name'];
          }
      } catch (PDOException $e) {
          echo "Error occurred. Error message: ". $e-&gt;getMessage();
      }
  
      /* do more stuff... */
  }
  </code></pre>
  
  <p>As expected, the output returned is</p>
  
  <pre><code>$res_PR: array(2) {["PRcounter"]=&gt;string(1) "0" [0]=&gt;string(1) "0"}
  $res_TA: array(2) {["TAcounter"]=&gt;string(1) "0" [0]=&gt;string(1) "0"}
  $res_sites: array(211) {[0]=&gt;array(3) {["site_ID"]=&gt;string(1) "1" ["site_name"]=&gt;...}
  </code></pre>
  
  <p>This is one of several sections of code I'm working on.  I will be pulling a row back from 7 tables when the page loads. Is the above fine, or can the multiple statements be prepared and then executed in a single execute() statement?</p>
  
  <p>Many thanks.</p>