当我尝试使用我的Web应用程序访问数据库时,我得到:
mysqli :: mysqli():( HY000 / 1045):在C:\ xampp \ htdocs \ Forum \ accounts \ PlayerAccount \ Login.php中拒绝用户'php'@'localhost'(使用密码:YES)的访问权限在第4行 连接到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));
?>
答案 0 :(得分:2)
在Mysql
上通过line命令执行以下句子var options = {
xaxis: {
min: 3,
max: 5
}
}
它将授予访问您用于连接的用户的权限。
答案 1 :(得分:0)
你有mysql auth的问题。尝试使用用户名连接到您的数据库:root,密码:''(空字符串)。它是XAMPP默认值。