这段php代码怎么理解?
// user类中的方法:public static function getByUsername($username) {
$u = new User();
$query = sprintf('SELECT USER_ID, PASSWORD, EMAIL_ADDR, IS_ACTIVE ' .
'FROM %sUSER WHERE USERNAME = "%s"',
DB_TBL_PREFIX,
mysql_real_escape_string($username, $GLOBALS['DB']));
$result = mysql_query($query, $GLOBALS['DB']);
if (mysql_num_rows($result))
{
$row = mysql_fetch_assoc($result);
$u->username = $username;
$u->password = $row['PASSWORD'];
$u->emailAddr = $row['EMAIL_ADDR'];
$u->isActive = $row['IS_ACTIVE'];
$u->uid = $row['USER_ID'];
}
mysql_free_result($result);
return $u;
}
// register.php页面中:
$user = User::getByUsername($_POST['username']);
if ($user->userId)
{
$GLOBALS['TEMPLATE']['content'] = '<p><strong>Sorry, that ' .
'account already exists.</strong></p> <p>Please try a ' .
'different username.</p>';
$GLOBALS['TEMPLATE']['content'] .= $form;
}
else
{
// create an inactive user record
$u = new User();
$u->username = $_POST['username'];
$u->password = $password;
$u->emailAddr = $_POST['email'];
$token = $u->setInactive();
$GLOBALS['TEMPLATE']['content'] = '<p><strong>Thank you for ' .
'registering.</strong></p> <p>Be sure to verify your ' .
'account by visiting <a href="verify.php?uid=' .
$u->userId . '&token=' . $token . '">verify.php?uid=' .
$u->userId . '&token=' . $token . '</a></p>';
}
追问:$query = sprintf('SELECT USER_ID, PASSWORD, EMAIL_ADDR, IS_ACTIVE ' .
'FROM %sUSER WHERE USERNAME = "%s"',
DB_TBL_PREFIX,$GLOBALS['TEMPLATE']['content'] = '<p><strong>Sorry, that ' .
'account already exists.</strong></p> <p>Please try a ' .
'different username.</p>';
$GLOBALS['TEMPLATE']['content'] .= $form;