求錯誤 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
2017-08-14
catch括號中應該是Exception吧,你寫成Execption了