count vs mysql_num_rows

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I've got a little function that just checks to see if something is in a mysql db. There are several ways to do this and was curious as to the best way. The following are 2 (simplified) versions that work just fine. If these are the best ways, which of the following is better from a performance standpoint. And if there is a way that is better than one of these, I'd love to know what that is.

$query = "SELECT count(id) as count FROM wncci_intranet.iAdmin_users WHERE name = '$name' LIMIT 1";
$results = mysql_query($query);
$row = mysql_fetch_array($results);
$count = $row["count"];
return $count;

OR

$query = "SELECT id FROM wncci_intranet.iAdmin_users WHERE name = '$name' LIMIT 1";
$results = mysql_query($query);
$count = mysql_num_rows($results);
return $count;


Thanks.

--
Kevin Murphy
Webmaster: Information and Marketing Services
Western Nevada College
www.wnc.edu
775-445-3326

P.S. Please note that my e-mail and website address have changed from wncc.edu to wnc.edu.



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux