我試圖更新我的當前數據庫從純文本密碼哈希密碼使用crypt()
..我試圖做到這一點,用戶不必更改他們的密碼(這是一個不穩定的方法)我的代碼是像這樣:在一個while循環執行查詢.. MySQli
$Query = $Database->prepare("SELECT ID,Username,Password FROM userlist");
$Query->execute();
$Query->bind_result($ID,$Username,$Password);
while ($Query->fetch()){
$Hashed = $FrameWork->Hash_Password($Password);
$Secondary_Query = $Database->prepare("UPDATE userlist SET Password=?, Salt=? WHERE ID=?");
$Secondary_Query->bind_param('ssi', $Hashed['Password'],$Hashed['Salt'],$ID);
$Secondary_Query->execute();
$Secondary_Query->close();
}
$Query->close();
,我發現了錯誤:
Fatal error: Call to a member function bind_param() on a non-object in C:\inetpub\www\AdminChangeTextPass.php on line 24
現在。我知道我的專欄名稱與我的數據庫名稱完全一致。我也知道我的變量是正確設置的。
調試
調試:
$Query = $Database->prepare("SELECT ID,Username,Password FROM userlist");
$Query->execute();
$Query->bind_result($ID,$Username,$Password);
while ($Query->fetch()){
echo $Password."<br>";
}
$Query->close();
// Returns:
//test
//test
Then:
$Query = $Database->prepare("SELECT ID,Username,Password FROM userlist");
$Query->execute();
$Query->bind_result($ID,$Username,$Password);
while ($Query->fetch()){
print_r($FrameWork->Hash_Password($Password));
}
$Query->close();
/*
Returns:
Array ([Salt] => ÛûÂÒs8Q-h¸Ý>c"ÿò [Password] => Ûûj1QnM/Ui/16)
Array ([Salt] => ÛûÂÒs8Q-h¸Ý>c"ÿò [Password] => Ûûj1QnM/Ui/16)
*/
數據庫模式
CREATE TABLE IF NOT EXISTS `userlist` (
`ID` int(255) NOT NULL AUTO_INCREMENT,
`Username` varchar(255) NOT NULL,
`Password` varchar(255) NOT NULL,
`Salt` text NOT NULL,
PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=9 ;
--
-- Dumping data for table `userlist`
--
INSERT INTO `userlist` (`ID`, `Username`, `Password`, `Salt`) VALUES
(1, 'test', 'test', ''),
INSERT INTO `userlist` (`ID`, `Username`, `Password`, `Salt`) VALUES
(2, 'test', 'test', '');
有我的代碼如下所示:
個$Secondary_Query = $Database->prepare("UPDATE userlist SET Password=? WHERE ID=?");
$Query = $Database->prepare("SELECT ID,Username,Password FROM userlist LIMIT 1");
var_dump($Secondary_Query);
#$Query->execute();
#$Query->bind_result($ID,$Username,$Password);
# while ($Query->fetch()){
# $Hashed = $FrameWork->Hash_Password($Password);
# $Secondary_Query = $Database->prepare("UPDATE userlist SET Password=? WHERE ID=?");
# $Secondary_Query->bind_param('ssi', $Hashed['Password'],$Hashed['Salt'],$ID);
# $Secondary_Query->execute();
# $Secondary_Query->close();
# }
#$Query->close();
的var_dump($Secondary_Query);
回報:
object(mysqli_stmt)#3 (10) { ["affected_rows"]=> int(-1) ["insert_id"]=> int(0) ["num_rows"]=> int(0) ["param_count"]=> int(2)
["field_count"]=> int(0) ["errno"]=> int(0) ["error"]=> string(0) "" ["error_list"]=> array(0) { } ["sqlstate"]=> string(5) "00000" ["id"]=> int(1) }
而且var_dump($Query);
回報:
object(mysqli_stmt)#4 (10) { ["affected_rows"]=> int(-1) ["insert_id"]=> int(0) ["num_rows"]=> int(0) ["param_count"]=> int(0) ["field_count"]=> int(3) ["errno"]=> int(0) ["error"]=> string(0) "" ["error_list"]=> array(0) { } ["sqlstate"]=> string(5) "00000" ["id"]=> int(2) }
正如我不能提交答案的還..我的工作代碼如下:
$Query = $Database->prepare("SELECT ID,Username,Password FROM userlist");
$Query->execute();
$Query->bind_result($ID,$Username,$Password);
$Query->store_result();
while ($Query->fetch()){
$Hashed = $FrameWork->Hash_Password($Password);
$Secondary_Query = $Database->prepare("UPDATE userlist SET Password=?, Salt=? WHERE ID=?");
$Secondary_Query->bind_param('ssi', $Hashed['Password'],$Hashed['Salt'],$ID);
$Secondary_Query->execute();
$Secondary_Query->close();
}
$Query->close();
您正在調試錯誤的東西。問題是'$ Secondary_Query'看起來不是一個對象。什麼'print_r($ Secondary_Query);''返回後'$ Secondary_Query = $數據庫 - >準備(「更新用戶列表SET密碼= ?,鹽=?WHERE ID =?」);'? – rtcherry
另外,用戶應該有不同的ID值。 – rtcherry
@rtcherry Print_r($ Secondary_Query);返回空白..'Var_dump($ Secondary_Query);'返回:'布爾(假)' –