Home » Php » MySql Access denied for user ''@'localhost' to database

MySql Access denied for user ''@'localhost' to database

Posted by: admin October 29, 2018 Leave a comment

Questions:

I am trying to connect with Mysql using PHP. It works fine when I do it without a database. But gives me the following error when I try to connect with a database.

Warning: mysqli::__construct(): (HY000/1044): Access denied for user ”@’localhost’ to database ‘db_test’ in C:\xampp\htdocs\Projects\DemoProject\demo2.php on line 13
Connection failed: Access denied for user ”@’localhost’ to database ‘db_test’

My PHP code is given below.

<?php
$servername = "localhost";
$username = "username";
$password = "";
$dbname = "db_test";

$conn = new mysqli($servername, $username, $password, $dbname);

if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 
else 
    echo "Connected Successfully";
?>
Answers: