php xampp出现拒绝访问错误

ccgok5k5  于 2021-06-24  发布在  Mysql
关注(0)|答案(2)|浏览(421)

当我尝试使用web应用程序访问数据库时,我得到:
mysqli::mysqli():(hy000/1045):在c:\xampp\htdocs\forum\accounts\playeraccount\login.php的第4行中,对用户“php”@“localhost”的访问被拒绝(使用密码:是)连接到mysql数据库时出错(1045)对用户“php”@“localhost”的访问被拒绝(使用密码:是)
我没有将root用于应用程序。我让一个名为php的用户拥有所有权限。我正在使用xamppmysql数据库,但它仍然不起作用。
编辑:根据要求,以下是代码:

<?php

  function getAccountRow($uuid){
  $configs = include('config.php');
  $mysqli = new mysqli($configs["host"], $configs["username"], $configs["password"], "account");    if($mysqli->connect_errno){
      die("Error connecting to MySQL database (".$mysqli->connect_errno.") ".$mysqli->connect_error);
    }
    $stmt = $mysqli->prepare("SELECT * FROM accounts WHERE uuid = ?");
    $stmt->bind_param("s", $uuid);
    $stmt->execute();
    $res = $stmt->get_result();
    $row = $res->fetch_assoc();
    return $row;
  }
    $file = fopen("test.txt","a");
    $post_json = file_get_contents("php://input");
    $post = json_decode($post_json, true);
    foreach($post as $key=> $value) {
        $message = $key . ":" . $value . "\n";
        file_put_contents("login_test", $message);
        fwrite($file,$message);
    }
    fclose($file);
    $response = array();
  $row = getAccountRow($post["Uuid"]);
  if($row["id"] == NULL){
$configs = include('config.php');
  $mysqli = new mysqli($configs["host"], $configs["username"], $configs["password"], "Account");    if($mysqli->connect_errno){
      die("Error connecting to MySQL database (".$mysqli->connect_errno.") ".$mysqli->connect_error);
    }
    //$_stmt = $mysqli->prepare("INSERT INTO accounts (uuid, name) values(?, ?)");
    //$_stmt->bind_param("ss", $post["Uuid"], $post["Name"]);
    //$_stmt->execute();
  }
  $row = getAccountRow($post["Uuid"]);
  $_rankperm = $row["rankPerm"];
  $rperm = false;
  if($_rankperm == 1){
    $rperm = true;
  }
  $response["AccountId"] = $row["id"];
  $response["Name"] = $row["name"];
  $response["Rank"] = $row["rank"];

  $response["RankPerm"] = $rperm;
  $response["RankExpire"] = (int) $row["rankExpire"];
  $response["EconomyBalance"] = 100;
  $response["LastLogin"] = (int) $row["lastLogin"];

    die(json_encode($response));
?>
pes8fvy9

pes8fvy91#

在mysql上通过line命令执行以下语句

> grant all privileges on your-database-name.* to 'php'@'localhost'  identified by 'your_pass_here';
> flush privileges;

它将授予您访问用于连接的用户的权限。

ar7v8xwq

ar7v8xwq2#

您对mysql auth有问题。尝试使用用户名:root,密码:“”(空字符串)连接到数据库。它是xampp默认值。

相关问题