First of all, declare that the database is normal. The primary key of the user table is incremented. Please answer.
Fatal error: Uncaught exception 'Exception' with message 'Registration failed' 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
Code
public function register($username,$password)
{
if (empty($ Username)) {
Throw New Exception ('Username cannot be empty', errorCode :: username_cannot_empty);
}
if (Empty ($ Password)) {
Throw New Excee) PTION ('Password Cannot be empty', ErrorCode::PASSWORD_CANNOT_EMPTY);
} }
if ($this->_isUsernameExists($username)) {
Throw new Exception('Username already exists', ErrorCode::USERNAME_EXISTS ; 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 {
throwing New Exception ('Register failed', errorCode :: register_fail);
} cach (Execption $ E) {
echo $ e-& gt; getMessage ();
}
# }
return[
'userid' => $this->_db->lastInsertId(),
use using using using using ‐ out out out through out's ‐ ‐ ‐ ‐ ‐ to return[
‐ ‐ ‐ ‐ 'userid' => ; $password,
'createdAt' => $createdAt
];
}
It seems a bit confusing, or you can take a screenshot or add code highlighting!
$stmt->execute(), an error will be reported when this step is executed. You can debug it with breakpoints and dump it step by step to see where the problem is