致命错误:在 D:\phpStudy\WWW\api\lib\User.php:84 中未捕获异常'异常”,消息为'注册失败”:84 堆栈跟踪:#0 D:\phpStudy\WWW\api\index.php(6 ): 用户->注册('admin1', 'admin1') #1 {main}
dahai
dahai 2017-08-12 00:01:30
0
1
1389

首先声明数据库是正常的,user表主键自增,求解答

 报错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

代码

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
       ];
   }

dahai
dahai

kaiche

全部回复(1)
ringa_lee

看的有点头大,或者 你可以截图,或者加个代码高亮嘛!

$stmt->execute(),这一步执行的时候就报错了,你再往前断点调试一下,一步一步往上dump一下,看是哪个地方出个问题

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板