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 ?

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

  • 4 weeks later...

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.