gpt4 book ai didi

php - mysql_connect() : Access denied for user 'root'

转载 作者:行者123 更新时间:2023-11-29 19:22:41 24 4
gpt4 key购买 nike

伙计们,我遇到了共同的问题。我想使用 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(): Access denied for user 'root'@'XXX' (using password: NO) in C:\xampp\htdocs\html.php on line 16 Access denied for user 'root'@'Dell' (using password: NO)

我更改了密码,出现同样的错误

mysql_connect(): Access denied for user 'root'@'XXX' (using password: YES) in C:\xampp\htdocs\html.php on line 16 Access denied for user 'root'@'Dell' (using password: YES)

我不知道该怎么办

最佳答案

您的连接字符串正在使用 IP 地址,并且 root 未配置为通过您用于主机的 IP 地址进行访问。您必须将其更改为 localhost 或将该权限添加到 root 用户的 mysql 服务器。

我建议你不要这样做,而是为你的开发创建一个新的 mysql 用户。

此外,来自@sidyll,您将不想使用 mysql_* 函数并使用 PDO 函数。

关于php - mysql_connect() : Access denied for user 'root' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42354402/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com