求错误 Fatal error: Uncaught exception 'Exception' with message '注册失败' in D:\phpStudy\WWW\api\lib\User.php:84 Stack trace: #0 D:\phpStudy\WWW\api\index.php(6): User->register('admin1', 'admin1') #1 {main} thrown in D:\phpStudy\WWW\api\lib\User.php on line 84
/**
*用户注册
* @param $usernama
* @param $password
*/
public function register($username,$password)
{
if (empty($username)) {
throw new Exception('用户名不能为空', ErrorCode::USERNAME_CANNOT_EMPTY);
}
if (empty($password)) {
throw new Exception('密码不能为空', ErrorCode::PASSWORD_CANNOT_EMPTY);
}
if ($this->_isUsernameExists($username)) {
throw new Exception('用户名已存在', ErrorCode::USERNAME_EXISTS);
}
//写入数据库
$sql = 'insert into user (username,password,createdAt) values(:username,:password,:createdAt)';
$createdAt = time();
$password = $this->_md5($password);
// var_dump($password);exit();
$stmt = $this->_db->prepare($sql);
$stmt->bindParam(':username', $username);
$stmt->bindParam(':password', $password);
$stmt->bindParam(':createdAt', $createdAt);
// print_r($stmt);exit();
if (!$stmt->execute()) {
try{
throw new Exception('注册失败',ErrorCode::REGISTER_FAIL);
} catch (Execption $e) {
echo $e->getMessage();
}
}
return[
'userId' => $this->_db->lastInsertId(),
'username' => $username,
'password' => $password,
'createdAt' => $createdAt
];
}
Fatal error: Uncaught exception 'Exception' with message '注册失败' in D:\phpStudy\WWW\api\lib\User.php:84 Stack trace: #0 D:\phpStudy\WWW\api\index.php(6): User->register('admin1', 'admin1') #1 {main} thrown in D:\phpStudy\WWW\api\lib\User.php on line 84