先宣告資料庫是正常的,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);
word> ## # throw new Exception('密碼不能為空', ErrorCode::PASSWORD_CANNOT_EMPTY);
}
if ($this->_isUsernameExists($ name)) {## if ($this->_isUsernameExists($ name)) {## or 有名。 ME_EXISTS );
}
//寫入資料庫
$sql = 'insert into user (username,password,createdAtAt) values(: name,Atcreated, created ); time();
$password = $this->_md5($password);
// var_dump($password);exit();## > ;prepare($sql);
$stmt->bindParam(':username', $username);
$stmt->bindParam(':password', $9 );## pass ); ->bindParam(':createdAt', $createdAt);
// print_r($stmt);exit();
# if (!$stmt-> # try{
throw new Exception('註冊失敗',ErrorCode::REGISTER_FAIL);
echo $e->getMessage();
}
}
return[
'userid' => $this->_db->lastInsertId(),
'username' => $username,
'password' => ; $password,
'createdAt' => $createdAt
];
}
看的有點頭大,或是 你可以截圖,或是加個程式碼高亮嘛!
$stmt->execute(),這一步執行的時候就報錯了,你再往前斷點調試一下,一步一步往上dump一下,看是哪個地方出個問題