我正在关注youtube上由 tonakami TV 制作登录注册表的教程,我遇到了一个问题,即Android应用程序无法通过LOCALHOST XAMPP更新或连接到数据库。有一个星期我一直在寻找所有可能的解决方案,但没有找到。也许你们可以帮我解决我的PHP文件问题( register.php 和 fetchuserdata.php ),我也发现我在php中也有这个错误files: mysqli_connect():( HY000 / 1044):用户'my_user'@'localhost'拒绝访问数据库'my_db'。我授予所有权限,但仍然无法连接,我不知道问题是来自PHP文件,android studio或XAMPP localhost phpmyadmin中服务器的链接。谢谢!
Screenshot of Android Studio: highlighted link
<?php
$con=mysqli_connect("localhost","my_user","my_password","my_db");
$name = $_POST["name"];
$age = $_POST["age"];
$username = $_POST["username"];
$password = $_POST["password"];
$statement = mysqli_prepare($con, "INSERT INTO User (name, age, username, password) VALUES (?, ?, ?, ?)");
mysqli_stmt_bind_param($statement, "siss", $name, $age, $username, $password);
mysqli_stmt_execute($statement);
mysqli_stmt_close($statement);
mysqli_close($con);
?>
<?php
$con=mysqli_connect("localhost","my_user","my_password","my_db");
$username = $_POST["username"];
$password = $_POST["password"];
$statement = mysqli_prepare($con, "SELECT * FROM User WHERE username = ? AND password = ?");
mysqli_stmt_bind_param($statement, "ss", $username, $password);
mysqli_stmt_execute($statement);
mysqli_stmt_store_result($statement);
mysqli_stmt_bind_result($statement, $userID, $name, $age, $username, $password);
$user = array();
while(mysqli_stmt_fetch($statement)){
$user["name"] = $name;
$user["age"] = $age;
$user["username"] = $username;
$user["password"] = $password;
}
echo json_encode($user);
mysqli_close($con);
?>