if (! $stmt->execute()) { throw new Exception('注册失败', ErrorCode::REGISTER_FAIL); } 一直报错,通过print $this->_db->errorCode();查看到错误代码00000又没有错,这是怎么回事?
字段 createdAt 改成 created_at
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
];
是不是没commit