Moez Posted September 21, 2014 Share Posted September 21, 2014 define("DB_HOST", "localhost"); define("DB_USERNAME", "locahhost'@'root "); define("DB_PASSWORD", NULL); define("DB_DATABASE", "poll"); if (!$db = @mysqli_connect(DB_HOST,DB_USERNAME,DB_PASSWORD,DB_DATABASE)) { echo 'Could not connect to db<br />'; exit; Quote Link to comment https://forums.phpfreaks.com/topic/291204-could-not-connect-to-db/ Share on other sites More sharing options...
requinix Posted September 21, 2014 Share Posted September 21, 2014 The username is just the user portion. No quotes or @host. Quote Link to comment https://forums.phpfreaks.com/topic/291204-could-not-connect-to-db/#findComment-1491735 Share on other sites More sharing options...
Jacques1 Posted September 21, 2014 Share Posted September 21, 2014 Even if you did have to include the host (which you don't), what on earth is locahhost'@'root What is “locahhost”? Where are the closing quotes? Why is your format host@user instead of user@host? Please, Moez. At least read your code before you ask others to fix it. And it doesn't hurt to write down a proper error description instead of just dumping the code. Lazy people aren't exactly popular in help forums. Quote Link to comment https://forums.phpfreaks.com/topic/291204-could-not-connect-to-db/#findComment-1491744 Share on other sites More sharing options...
Moez Posted September 21, 2014 Author Share Posted September 21, 2014 if i use define("DB_USERNAME", "root "); also same error username is root Quote Link to comment https://forums.phpfreaks.com/topic/291204-could-not-connect-to-db/#findComment-1491754 Share on other sites More sharing options...
mac_gyver Posted September 21, 2014 Share Posted September 21, 2014 you are putting a space on the end of the DB_USERNAME defined constant. if your code (for debugging/learning) was making use the php warning from that statement or the mysqli_connect_error() message you would probably be able to see it in the error message - Access denied for user 'root '@'localhost' (using password: YES) ^ in programming, every character matters and in this case an extra character that's not present in the actual value causes the connection to fail. this is no different than if your code had define("DB_USERNAME", "roota");. that's not what the username is. Quote Link to comment https://forums.phpfreaks.com/topic/291204-could-not-connect-to-db/#findComment-1491761 Share on other sites More sharing options...
CroNiX Posted September 21, 2014 Share Posted September 21, 2014 It would help to remove your error suppressing @ from mysqli_connect...big NO NO. Quote Link to comment https://forums.phpfreaks.com/topic/291204-could-not-connect-to-db/#findComment-1491771 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.