伙计们我有共同的问题。我想使用PHP将数据从MySQL数据库显示到HTML中。
使用此代码:
<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():用户'root'@'XXX‘的访问被拒绝(使用密码: NO)在第16行的C:\xampp\htdocs\html.php中,用户'root'@'Dell’被拒绝访问(使用密码: NO)
我更改了密码,出现了相同的错误。
mysql_connect():用户'root'@'XXX‘的访问被拒绝(使用密码:是)在第16行的C:\xampp\htdocs\html.php中,用户'root'@'Dell’被拒绝访问(使用密码:是)
该怎么办呢
发布于 2017-02-20 21:33:45
试试这个:
mysql_connect($servername,'root','','database') or die (mysql_error ());https://stackoverflow.com/questions/42354402
复制相似问题