不能向數(shù)據(jù)庫(kù)插入數(shù)據(jù)
if (! $stmt->execute()) { ? ? ? ? ? ?throw new Exception('注冊(cè)失敗', ErrorCode::REGISTER_FAIL); ? ? ? ?} 一直報(bào)錯(cuò),通過(guò)print $this->_db->errorCode();查看到錯(cuò)誤代碼00000又沒(méi)有錯(cuò),這是怎么回事?
if (! $stmt->execute()) { ? ? ? ? ? ?throw new Exception('注冊(cè)失敗', ErrorCode::REGISTER_FAIL); ? ? ? ?} 一直報(bào)錯(cuò),通過(guò)print $this->_db->errorCode();查看到錯(cuò)誤代碼00000又沒(méi)有錯(cuò),這是怎么回事?
2017-04-16
舉報(bào)
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('用戶名已經(jīng)存在', ErrorCode::USERNAME_EXISTS);
? ? ? ? }
? ? ? ? // 寫(xiě)入數(shù)據(jù)庫(kù)
? ? ? ? $sql = 'INSERT INTO `user`(`username`, `password`, `createdAt`) VALUES(:username,:password,:ceatedAt)';
? ? ? ? $ceatedAt = time();
? ? ? ? $password = $this->_md5($password);
? ? ? ??
? ? ? ? $stmt = $this->_db->prepare($sql); // 解析sql語(yǔ)句
? ? ? ??
? ? ? ? $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('注冊(cè)失敗', ErrorCode::REGISTER_FAIL);
? ? ? ? }
? ? ? ??
? ? ? ? return [
? ? ? ? ? ? 'id' => $this->_db->lastInsertId(),
? ? ? ? ? ? 'username' => $username,
? ? ? ? ? ? 'ceatedAt' => $ceatedAt
? ? ? ? ];
2017-04-16
是不是沒(méi)commit