Jump to content

Could not connect to db


Moez

Recommended Posts

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;

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.