我刚刚安装了xampp,并且正在phpMyAdmin上本地运行MySQL数据库。我正在尝试通过.php doc输出数据库的内容,但是在尝试这样做时会收到两个警告:
警告:mysqli :: __ construct():服务器在第20行的C:\ xampp \ htdocs \ footfallTracker \ test.php中请求客户端[caching_sha2_password]未知的身份验证方法
警告:mysqli :: __ construct():(HY000 / 2054):服务器在第20行的C:\ xampp \ htdocs \ footfallTracker \ test.php中请求客户端未知的身份验证方法 连接失败:服务器请求客户端未知的身份验证方法
这是我正在使用的代码:
<?php
$servername = "localhost";
$username = "root";
$password = "*2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19";
$dbname = "footfall_tracking";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT ID, Location, Date FROM footstep_count";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo "ID: " . $row["ID"]. " - Location: " . $row["Location"]. " - Date: " . $row["Date"]. "<br>";
}
} else {
echo "0 results";
}
$conn->close();
?>
答案 0 :(得分:0)
这段代码对我有帮助
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password
BY 'password';
您可以在这里检查它:D The server requested authentication method unknown to the client (PHP)