我都想盡解決方案在這裏找到答案和許多其他論壇,但連接到MySQL數據庫使用PHP連接使用PHP
當一切都是徒勞我仍然有錯誤的MySQL數據庫無法連接:拒絕訪問用戶'根' @ 'localhost' 的(使用密碼:NO)
這裏是我的PHP腳本
<?php
$database="test"; //database name
$Uname=$_POST['username'];//this values comes from html file after submitting
$Pwd=$_POST['pwd'];
$con = mysql_connect("127.0.0.1","root" ,"zain");//for wamp 3rd feild is balnk
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("$database", $con);
$query = "INSERT INTO data (UserName,Password)VALUES ('$Uname','$Pwd')";
mysql_query($query);
echo "<script type='text/javascript'>\n";
echo "alert('you are Succesflly registered');
\n";
echo "</script>";
mysql_close();
和我php.config文件是這樣
/* Server: localhost [1] */
$i++;
$cfg['Servers'][$i]['verbose'] = 'localhost';
$cfg['Servers'][$i]['host'] = 'localhost';
$cfg['Servers'][$i]['port'] = '';
$cfg['Servers'][$i]['socket'] = '';
$cfg['Servers'][$i]['connect_type'] = 'tcp';
$cfg['Servers'][$i]['extension'] = 'mysqli';
$cfg['Servers'][$i]['auth_type'] = 'config';
$cfg['Servers'][$i]['user'] = 'root';
$cfg['Servers'][$i]['password'] = 'zain';
$cfg['Servers'][$i]['AllowNoPassword'] = false;
你可能要檢查http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php/12860046#12860046和http:/ /stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php/60496#60496因爲您使用的是棄用函數(過去5年一直不鼓勵),您的代碼是開放給SQL注入,這意味着惡意用戶可以簡單地改變甚至刪除你的數據。 – Oldskool
通過phpMyAdmin創建一個新用戶,併爲其授予對所需數據庫或所有數據庫的完全權限。然後在config.inc.php中輸入您爲新用戶提供的用戶名和密碼。 –
現在更改密碼 – Strawberry