0
我有一个名为getUser
的方法,如果参数中提供的用户名存在,它只会从数据库中提取记录。下面是方法:密码被返回为NULL ...?
public function getUser($username)
{
$userInfo = array(
'username' => $username
);
if (! $stmt = $this->Connection()->prepare("SELECT * FROM " . $this->_info['Prefix'] . "users
WHERE `".implode("`, `", array_keys($userInfo))."` = ?"))
{
echo 'Prepare Failed: ' . $stmt->error . '<br />';
return FALSE;
}
if (! $stmt->bind_param('s', $userInfo['username']))
{
echo 'Bind Failed: ' . $stmt->error . '<br />';
return FALSE;
}
if (! $stmt->execute())
{
echo 'Execute Failed: ' . $stmt->error . '<br />';
return FALSE;
}
$stmt->store_result();
if ($stmt->num_rows == 0)
{
$this->_user['exists'] = FALSE;
}
else
{
$this->_user['exists'] = TRUE;
}
$stmt->bind_result($username, $password);
$stmt->fetch();
$this->_user['username'] = $username;
$this->_user['password'] = $password;
$stmt->close();
return $this->_user;
}
正如你可以在方法的结尾看到我返回_user
阵列我在叫checkPassword
另一种方法使用。这是它出错的地方,我的意思是密码是NULL
。为了确保这个查询没有错误,我输出了用户名(这是从getUser
方法返回的),它是正确的。所以我知道查询正在执行并存储值,但密码正在以NULL
的形式返回。这里是checkPassword
方法:
public function checkPassword($username, $password)
{
$info = $this->getUser($username);
if ($info['exists'] == FALSE) {
exit('The specified user does not exist!');
}
if (password_verify($password, $info['password']))
{
echo 'YAY';
}
else
{
echo 'NAY';
}
}
正如你可能已经猜到输出我得到的是NAY
即使密码是正确的。当我查看$info['password']
的值时,它只是NULL
。
为什么密码被返回为NULL
?