Jump to content

database connection failed: Access denied for user ''@'localhost' (using password: NO) (1045)


ronc0011

Recommended Posts

The deal is I know for fact the username and password are good. BTW I’m doing all this on my laptop. Apache, MySQL, & PHP are all installed and running locally.
 
I have a DB named “users” that I created under the root user account with a password of “r00t” now I can run a “SELECT * FROM “ with those credentials using the command line tool that ships with MySQL no problem it show all records in the users table. But the PHP script throws this error

<?php

   $dbhost = "localhost";
   $dbuser = "root";
   $dbpass = "r00";
   $dbname = "users";
   $conn = mysqli_connect ($host, $user, $pass, $name);

// Test if connection occured This is where we do our error trapping
   
   if(mysqli_connect_errno()) {
     die ("database connection failed: " .
      mysqli_connect_error() .
      " (" . mysqli_connect_errno() . ")"
     );
}
?>

OK, this is what I got and I think you'll be able to see I do have a user name and password...

 

 

 

 

 

You named the variable wrong

 

this

$conn = mysqli_connect ($host, $user, $pass, $name);

should be

$conn = mysqli_connect ($dbhost, $dbuser, $dbpass, $dbname);

Well I guess I feel pretty dumb. Just too long staring at this stuff. Also different environment than what I was used to . I changed from a desktop with dual monitors to a laptop with a single 15” monitor. I’m actually used to being able to see what I’m doing. Well thank you for your help. That’s what I needed was a pair of good eyes.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.