ronc0011 Posted February 27, 2015 Share Posted February 27, 2015 (edited) 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 Edited February 28, 2015 by mac_gyver fixed font usage Quote Link to comment https://forums.phpfreaks.com/topic/294951-database-connection-failed-access-denied-for-user-localhost-using-password-no-1045/ Share on other sites More sharing options...
requinix Posted February 28, 2015 Share Posted February 28, 2015 As you should be able to see in the error message, you aren't actually specifying a username or password. You need to do that. Quote Link to comment https://forums.phpfreaks.com/topic/294951-database-connection-failed-access-denied-for-user-localhost-using-password-no-1045/#findComment-1507013 Share on other sites More sharing options...
Psycho Posted February 28, 2015 Share Posted February 28, 2015 You are probably including variables in the connection function, but they are not defined when that line is run. Quote Link to comment https://forums.phpfreaks.com/topic/294951-database-connection-failed-access-denied-for-user-localhost-using-password-no-1045/#findComment-1507017 Share on other sites More sharing options...
ronc0011 Posted February 28, 2015 Author Share Posted February 28, 2015 (edited) <?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... Edited February 28, 2015 by ronc0011 Quote Link to comment https://forums.phpfreaks.com/topic/294951-database-connection-failed-access-denied-for-user-localhost-using-password-no-1045/#findComment-1507029 Share on other sites More sharing options...
QuickOldCar Posted February 28, 2015 Share Posted February 28, 2015 You named the variable wrong this $conn = mysqli_connect ($host, $user, $pass, $name); should be $conn = mysqli_connect ($dbhost, $dbuser, $dbpass, $dbname); Quote Link to comment https://forums.phpfreaks.com/topic/294951-database-connection-failed-access-denied-for-user-localhost-using-password-no-1045/#findComment-1507030 Share on other sites More sharing options...
ronc0011 Posted February 28, 2015 Author Share Posted February 28, 2015 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. Quote Link to comment https://forums.phpfreaks.com/topic/294951-database-connection-failed-access-denied-for-user-localhost-using-password-no-1045/#findComment-1507057 Share on other sites More sharing options...
Barand Posted February 28, 2015 Share Posted February 28, 2015 That’s what I needed was a pair of good eyes. ... and PHP's error reporting turned on to warn you when you use a variable that is undefined. Quote Link to comment https://forums.phpfreaks.com/topic/294951-database-connection-failed-access-denied-for-user-localhost-using-password-no-1045/#findComment-1507076 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.