count vs mysql_num_rows

From: Date: Mon, 08 Oct 2007 18:47:00 +0000
Subject: count vs mysql_num_rows
Groups: php.general 
Request: Send a blank email to php-general+get-262923@lists.php.net to get a copy of this message
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.

« previous php.general (#262923) next »