Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/291.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
php xampp的访问被拒绝错误_Php_Mysql_Xampp - Fatal编程技术网

php xampp的访问被拒绝错误

php xampp的访问被拒绝错误,php,mysql,xampp,Php,Mysql,Xampp,当我尝试使用web应用程序访问数据库时,我得到: mysqli::mysqli():(HY000/1045):第4行C:\xampp\htdocs\Forum\accounts\PlayerAccount\Login.php中的用户“php”@“localhost”(使用密码:YES)的访问被拒绝 连接到MySQL数据库(1045)时出错,用户“php”@“localhost”的访问被拒绝(使用密码:YES) 我没有在应用程序中使用root。我让一个名为PHP的用户拥有所有权限。我正在使用xam

当我尝试使用web应用程序访问数据库时,我得到:

mysqli::mysqli():(HY000/1045):第4行C:\xampp\htdocs\Forum\accounts\PlayerAccount\Login.php中的用户“php”@“localhost”(使用密码:YES)的访问被拒绝 连接到MySQL数据库(1045)时出错,用户“php”@“localhost”的访问被拒绝(使用密码:YES)

我没有在应用程序中使用root。我让一个名为PHP的用户拥有所有权限。我正在使用xampp mysql数据库,但它仍然不工作

编辑:根据要求,以下是代码:

<?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));
?>

在Mysql上通过line命令执行以下句子

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

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

您的mysql身份验证有问题。尝试使用用户名:root,密码:“”(空字符串)连接到数据库。这是XAMPP默认值。

然后猜测您拼写了错误的密码,或者您设置了错误的用户,或者您创建了一个名为PHP的用户,并在
PHP
的代码中使用了用户ID。添加该用户后是否刷新了权限?似乎您没有将根用户设置为您的连接,你能公开你用来连接的代码吗?@OscarDavid他说他没有使用
root
这不是使用
root
的先决条件,事实上这是人们犯的新手错误之一确保你的用户名和密码是正确的。如果必须,请重置它。确保用户/主机组合对
帐户
数据库具有权限,现在,添加
更改用户'php'@'localhost'密码永不过期
可能会很有用,或者在30天后,它可能会再次停止工作,并对最近的mysql 5.7更改发表评论将所有内容都添加到所有数据库是一个巨大的安全漏洞。只应将其设置为所需的数据库。Heard Heart@aynberHow我使用phpMyAdmin执行该操作如果您有根用户,只需作为SQL执行,但如果您使用的是共享服务,则可以尝试通过向导向用户授予权限。我知道您缺少代表,但这实际上只是一个注释。这种类型的回答会吸引反对票或被标记我没有DV,如果发生这种情况,你将失去代表分数,需要更长的时间才能获得50个代表,你需要对任何问题进行评论。在那之前,坚持问得好的问题,因此不需要澄清就可以轻松回答。谢谢你的反馈)我知道这种回答不好)但我不能写评论:D