我有
$salt = md5(mt_rand());
$hashed = hash_hmac('SHA256', $password, $salt);
$stmt = self::$_dbh->prepare('INSERT INTO users (username, password, salt, display, email) VALUES (:username, :password, :salt, :display, :email)');
$stmt->bindParam('username', $username);
$stmt->bindParam('password', $hashed);
$stmt->bindParam('salt', $salt);
$stmt->bindParam('display', $display);
$stmt->bindParam('email', $email);
$stmt->execute();
$firephp->log('Insert OK ');
if ($stmt->rowCount() > 0) {
return array(
'status' => 'OK',
'message' => 'Registration Successful'
);
}
$firephp->log('Unknown ... Row count: ' . $stmt->rowCount());
return array(
'status' => 'failed',
'message' => 'Something went wrong with the registration ... Please try again ...'
);
我总是得到“登记出了问题......请再试一次......”。看起来rowCount
是0.真的,它不会插入到数据库中。那是为什么?
答案 0 :(得分:3)
尝试:
$firephp->log(
$stmt->debugDumpParams()
. "\n"
. var_export($stmt->errorInfo());
答案 1 :(得分:0)
尝试将冒号放在bindParam占位符中,而不是
$stmt->bindParam('username', $username);
做
$stmt->bindParam(':username', $username);
希望它有所帮助!
答案 2 :(得分:0)
当有人在主ID字段上关闭/取消数据库自动增量时,可能会出现类似的问题。查看数据库并确保其设置正确。