用户访问被拒绝' my_user' @' localhost' (使用密码:是)

时间:2015-04-25 13:38:09

标签: php mysqli connection

有人可以解释这意味着什么以及我可以做些什么来解决它?

错误:

  

拒绝访问用户' my_user' @' localhost' (使用密码:是)

我的php文件:

<?php
    $mysqli = new mysqli("localhost", "my_user", "my_password", "my_db");

    $password = $_POST["password"];
    $username = $_POST["username"];

    $statement = mysqli_prepare(mysqli, "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_stmt_close($statement);


    mysqli_close(mysqli);

?>

1 个答案:

答案 0 :(得分:0)

您的数据库用户或密码错误(或两者都有)。再次检查用户是否存在该主机上的该数据库。

同时检查字符大小写。