不能向數據庫插入數據
if (! $stmt->execute()) { ? ? ? ? ? ?throw new Exception('注冊失敗', ErrorCode::REGISTER_FAIL); ? ? ? ?} 一直報錯,通過print $this->_db->errorCode();查看到錯誤代碼00000又沒有錯,這是怎么回事?
if (! $stmt->execute()) { ? ? ? ? ? ?throw new Exception('注冊失敗', ErrorCode::REGISTER_FAIL); ? ? ? ?} 一直報錯,通過print $this->_db->errorCode();查看到錯誤代碼00000又沒有錯,這是怎么回事?
2017-04-16
舉報
2018-11-25
字段?createdAt 改成 created_at
2017-04-17
? ? ? if (empty($username)) {
? ? ? ? ? ? throw new Exception('用戶名不能為空', ErrorCode::PASSWORD_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,:ceatedAt)';
? ? ? ? $ceatedAt = time();
? ? ? ? $password = $this->_md5($password);
? ? ? ??
? ? ? ? $stmt = $this->_db->prepare($sql); // 解析sql語句
? ? ? ??
? ? ? ? $stmt->bindParam(':username', $username);
? ? ? ? $stmt->bindParam(':password', $password);
? ? ? ? $stmt->bindParam(':ceatedAt', $ceatedAt);
? ? ? ??
? ? ? ? if (! $stmt->execute()) {
? ? ? ? ? ? print $this->_db->errorCode();
? ? ? ? ? ? print_r($this->_db->errorInfo());
? ? ? ? ? ? throw new Exception('注冊失敗', ErrorCode::REGISTER_FAIL);
? ? ? ? }
? ? ? ??
? ? ? ? return [
? ? ? ? ? ? 'id' => $this->_db->lastInsertId(),
? ? ? ? ? ? 'username' => $username,
? ? ? ? ? ? 'ceatedAt' => $ceatedAt
? ? ? ? ];
2017-04-16
是不是沒commit