为了账号安全,请及时绑定邮箱和手机立即绑定

求错误 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

正在回答

1 回答

catch括号中应该是Exception吧,你写成Execption了

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

求错误 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

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信