How to check for EOF in MySQL

In ASP, I can check for an End-Of-File condition by using

rs.EOF     ' returns True or False

For example, if I’m verifying if a certain UserName exists in the database, I can do a SELECT * FROM query, and check if rs.EOF.  If it’s rs.EOF, then I know the UserName is unique in the database.

In PHP/MySQL, to check for an end-of-file condition, count the number of rows returned by the query.

$query = "SELECT UserName FROM UserDB WHERE UserName='$UserName'";
$result = mysql_query($query);
// is a match found?
if (mysql_num_rows($result)){
  // match is found in UserDB, not unique name
  return FALSE;
} else {
  return TRUE;
}
This entry was posted in sql. Bookmark the permalink.