0

Whenever I try to connect to my database with my credentials, it doesn't connect with the username, for example when I try to connect to my local database with

mysqli_connect("localhost","dbuser","","database")

It returns

Warning: mysqli_connect(): (HY000/1044): Access denied for user ''@'localhost' to database 'database'
  • Possible duplicate of [Warning: mysqli\_connect(): (HY000/1045): Access denied for user 'username'@'localhost' (using password: YES)](https://stackoverflow.com/questions/25174183/warning-mysqli-connect-hy000-1045-access-denied-for-user-usernameloca) – knizer Jul 16 '17 at 05:38

2 Answers2

0

You can't connect using all four parameters on mysqli_connect() From the above code i can tell your

host : "localhost"
user: "dbuser"
password: ""
database name: "database"

Do this,

$conn = mysqli_connect("localhost", "dbuser", "");
mysqli_select_db($conn, "database");
// to check if you're connected, after tested and see you can take off the code below...
if ($conn) {
  echo "Connected";
} else {
  echo "Connection failed";
}

if you seriously want to connect using all four parameter above?

$conn = new mysqli("localhost","dbuser","","database");
// to check if you're connected, after tested and see you can take off the code below...
if ($conn) {
  echo "Connected";
} else {
  echo "Failed";
}

Hope this was helpful?

Precious Tom
  • 486
  • 3
  • 18
0

Just put a space between the quotes like this " " instead of "" to show as blank in the password value in your query because in programming a value either 0(false) or 1(true) has to be there you cannot have nothing and expect something

This is when you have not set password for the user in your local phpmyadmin like root user and also check for spelling mistakes