夥計們,我有一個共同的問題。 我想使用PHP將數據從MySQL數據庫顯示到HTML頁面。mysql_connect():拒絕用戶'root'的訪問
使用此代碼:
<html>
<head>
<title>Pulse Sensor Data </title>
</head>
<body>
<?php
$servername = 'localhost';
$username = 'root';
$password = '';
// Connect to database server
mysql_connect('192.168.1.106','root','','database') or die (mysql_error());
// Select database
mysql_select_db('database') or die(mysql_error());
// SQL query
$strSQL = "SELECT * FROM pulsesensor";
// Execute the query (the recordset $rs contains the result)
$rs = mysql_query($strSQL);
// Loop the recordset $rs
while($row = mysql_fetch_array($rs)) {
// Write the value of the column id and value
echo $row['id'] . " " . $row['value'] . "<br />";
}
// Close the database connection
mysql_close();
?>
</body>
</html>
,但我得到
mysql_connect()函數:在C:拒絕訪問用戶 '根' @ 'XXX'(沒有使用密碼):\ XAMPP \ htdocs中\ html.php第16次 訪問被拒絕的用戶「根」 @「戴爾(使用密碼:否)
我改變了密碼相同的錯誤出現
mysql_connect()函數:訪問被拒絕的用戶 '根' @ 'XXX'(使用密碼:是)在C:\ XAMPP \ htdocs中\ html.php第16次 訪問被拒絕的用戶 '根' @」戴爾(使用密碼:YES)
我不知道該怎麼辦
那麼你爲什麼要這樣分配'$服務器名稱= 'localhost' 的;'後使用'192.168.1.106'? –
你需要停止使用'mysql_ *'功能。它們已被棄用多年,甚至不存在於當前的PHP版本中。請研究[PHP數據對象](http://php.net/manual/en/intro.pdo.php),通常簡稱爲PDO。 – sidyll
可能的duplicateof http://stackoverflow.com/questions/8537531/access-denied-for-user-rootlocalhost-using-password-no –