Access denied for user in MySQL database
I have one user for two databases on my website. The first and older database DB_A is the real database, while the new DB_B is for testing purposes only.
My user, call him. USER_X has all privileges (except "DROP") on both of them, and I'm sure the username, password, and DB name are spelled correctly in PHP.
When connecting to DB_A and throwing, if(!mysql_select_db($dbname)) echo mysql_error();
I get nothing, in other words everything works fine.
When connecting to DB_B and throwing the same thing I get Access denied for user 'USER_X'@'localhost' to database 'DB_B'
.
Once again, I am confident that my credentials are correct and that I have all privileges on the DB_B database.
Anyone have an idea what's going on here?
Thank!
EDIT:
PHP v.5.2.17
MySQL v.5.0.96
source to share
Use MySQLi
- http://www.php.net/manual/en/book.mysqli.php - MySQL
deprecated.
It would be really helpful to see your real code!
Anyway, from http://www.php.net/manual/en/mysqli.connect-error.php
I suggest trying them out, if you still get the error then check the username, password and DB spelling are ok.
Object oriented style
$mysqli = @new mysqli('localhost', 'fake_user', 'my_password', 'my_db');
// Works as of PHP 5.2.9 and 5.3.0.
if ($mysqli->connect_error) {
die('Connect Error: ' . $mysqli->connect_error);
}
Procedural style
$link = @mysqli_connect('localhost', 'fake_user', 'my_password', 'my_db');
if (!$link) {
die('Connect Error: ' . mysqli_connect_error());
}
source to share