title: So what IS the best way to check if a row exists? EXISTS, COUNT or num_rows?
body: <p>If your only goal is to check if a row exists in php <strong>(true or false)</strong>, what is the best way to do it?</p>
  
  <p><strong>Option 1?</strong></p>
  
  <pre><code>$result = mysql_query("SELECT * FROM users WHERE id = '1'");
  $num_rows = mysql_num_rows($result);
  
  if ($num_rows == 1) 
      // one user, like it should be.
  
  else 
    // do something else
  </code></pre>
  
  <p><strong>Option 2?</strong></p>
  
  <pre><code>$query = mysql_query("select count(1) from users where id = 1")
  
  if (mysql_result($query, 0) == 1)
      // one user, like it should be.
  
  else 
    // do something else
  </code></pre>
  
  <p><strong>Option 3?</strong></p>
  
  <pre><code>$query = mysql_query("something like SELECT EXISTS( SELECT */1/COUNT(*)/etc. ...)")
  
  if (mysql_result($query, 0) == 1)
      // one user, like it should be.
  
  else 
    // do something else
  </code></pre>
  
  <p><strong>Beter option 4?</strong></p>
  
  <p>you name it.</p>
  
  <p><strong>Subquestions</strong></p>
  
  <ul>
  <li><code>COUNT(*), COUNT(1) or COUNT(id)</code>?</li>
  </ul>