Jump to content

[SOLVED] Trying to access mysql DB through PHP - Access denied. Err. # 1045


FeralReason

Recommended Posts

I am a newbie to mysql, running an XAMPP stack on Windows XP as a test environment and am trying to make my first connection to a mysql database using a connection script in "Sams Teach Yourself PHP, MySQL and Apache" by Julie Meloni. I successfully built the database, created the user and confirmed the user's existance by looking under the "privileges" tab in phpMyAdmin, where I saw this:

 

Users having access to "testDB": 

User    Host          Type                  Privileges          Grant  Action

jouser  localhost database-specific  ALL PRIVILEGES  No 

root    127.0.0.1 global  ALL PRIVILEGES  Yes 

root    localhost global  ALL PRIVILEGES  Yes 

 

Next I ran the script below:

 

<?php

$mysqli = new mysqli("localhost","jouser","somepass","testDB");

 

if(mysqli_connect_errno()) {

printf("Connect failed: %s\n", mysqli_connect_error());

exit();

} else {

printf("host information: %s\n", mysqli_get_host_info($mysqli));

}

?>

 

And then got this error:

 

Warning: mysqli::mysqli() [mysqli.mysqli]: (28000/1045): Access denied for user 'joeuser'@'localhost' (using password: YES) in C:\xampp\htdocs\mysqlconnect.php on line 2

Connect failed: Access denied for user 'joeuser'@'localhost' (using password: YES)

 

Although the author explains that this is the error you get if the connection fails, she provides no clue as to how to troubleshoot this.

 

Can anyone give me some help ?

Link to comment
Share on other sites

That's actually the error when the user does not have privileges to access that database (a connection error message is different.)

 

You need to execuite the fillowing to actually cause the previleges to take effect (note the Grant = NO value for the user you created) -

 

FLUSH PRIVILEGES

Link to comment
Share on other sites

  • 4 weeks later...
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.