I have a single user for two databases on my website. First and older database DB_A is real database while newer DB_B is just for testing purposes.
My user, let's call it USER_X has all privileges (except 'DROP') on both of them and I'm sure that my username, password and DB name are all written correctly within 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 connectin to DB_B and throwing the same thing, I get
Access denied for user 'USER_X'@'localhost' to database 'DB_B'.
Once again, I'm sure my credentials are correct and that I have all privileges on the DB_B database.
Anyone has an idea what's going on in here?
Thanks!
EDIT:
PHP v.5.2.17
MySQL v.5.0.96
解决方案
It would be really useful to see your actual code!
I suggest trying them, if you still get an error, then check 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());
}