title: Mysql SELECT COUNT(*) OR SELECT 1? PDO
body: <p>It has long been known that PDO does not support COUNT(*) and a query like below would fail as it doesn't return any affected rows,</p>
  
  <pre><code>$q = $dbc -&gt; prepare("SELECT COUNT(*) FROM table WHERE id = ?");
  $q -&gt; execute(array($id));
  echo $q -&gt; rowCount();
  </code></pre>
  
  <p>Doing some research I found that you can also get the row count using other methods of count and not using count at all, for example the following query is supposed be the same as above but will return correct for PDO,</p>
  
  <pre><code>$q = $dbc -&gt; prepare("SELECT 1 FROM table WHERE id = ?");
  $q -&gt; execute(array($id));
  echo $q -&gt; rowCount();
  </code></pre>
  
  <p>There are various sources on the internet claiming that;</p>
  
  <pre><code>"SELECT COUNT(*)
  "SELECT COUNT(col)
  "SELECT 1
  </code></pre>
  
  <p>Are all the same as each other (with a few differences) so how come using mysql which PDO cannot properly return a true count, does </p>
  
  <pre><code>"SELECT 1 
  </code></pre>
  
  <p>work?</p>
  
  <p><strong>Methods of count discussion</strong></p>
  
  <p><a href="https://stackoverflow.com/questions/1406099/why-is-select-1-faster-than-select-count">Why is Select 1 faster than Select count(*)?</a></p>