简体   繁体   English

即使在授予所有权限后,通过 XAMPP 使用 PHP 连接到 MySQL 时访问被拒绝

[英]Access denied when connecting to MySQL using PHP via XAMPP even after granting all privileges

I created a database 'college' and added an user 'neeraj' using 'localhost' with a password and granted all privileges on it.我创建了一个数据库“college”,并使用“localhost”和密码添加了一个用户“neeraj”,并授予了它的所有权限。 After executing the following php code, I got an error -执行以下 php 代码后,出现错误 -

Warning: mysqli_connect(): (HY000/1045): Access denied for user 'neeraj'@'localhost' (using password: YES) in F:\xampp\htdocs\tuts\index1.php on line 3
Connection error: Access denied for user 'neeraj'@'localhost' (using password: YES) Hello

PHP code - PHP 代码 -


$conn = mysqli_connect('localhost', 'neeraj', 'somneeraj99', 'college');

if(!$conn)
{
    echo 'Connection error: ' . mysqli_connect_error();
}

?>

<!DOCTYPE html>
<html>
Hello
</html>

I checked other answers but couldn't find a working solution.我检查了其他答案,但找不到有效的解决方案。 I created another user with the same details but set the host to '127.0.0.1:3307' and changed the host field of PHP code.我创建了另一个具有相同详细信息的用户,但将主机设置为“127.0.0.1:3307”并更改了 PHP 代码的主机字段。 This got rid of the error.这摆脱了错误。 But if I delete the previous localhost user, this doesn't work.但是,如果我删除以前的 localhost 用户,这将不起作用。

Rename the database, because in the question you say it is "colleges" but in your code is "college"重命名数据库,因为在问题中您说它是“colleges”,但在您的代码中是“college”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM