2015-04-03 165 views
0

嗨我更改mysql用戶密碼使用波紋管腳本但密碼不會更改。如何更改mysql用戶密碼?

$conn = mysqli_connect('host', 'root', 'password'); 
$dbUser = "username"; # same username as in your example 
$dbPass = "new_password"; # new password 

$queries = array(
    "USE mysql;", # switch to the 'mysql' database 
    "SET PASSWORD FOR '$dbUser'@'localhost' = PASSWORD('$dbPass');" 
); 

foreach($queries as $query) { 
    $rs = mysqli_query($conn, $query);   
} 

使用此腳本密碼不會更改,也不會顯示錯誤。

+0

你有些進步嗎? – 2015-05-01 18:50:18

回答

0

嘗試此查詢可能這將幫助你

mysql_query("UPDATE mysql.user SET Password = PASSWORD('$password') WHERE User='$username'"); 
0

剛剛嘗試此查詢

SET PASSWORD FOR 'bob'@'%.example.org' = PASSWORD('cleartext password'); 
+0

什麼是明文密碼? – 2015-04-03 10:47:51

1

試試這個,這也可以幫助SQL注入。

$query = sprintf("UPDATE mysql.user SET Password = '%s' WHERE User='%s'",mysqli_real_escape_string($dbPass),mysql_real_escape_string($dbUser)); 
$result = mysqli_query($query); 
if($result){ 
    echo "change success"; 
}