Page 1 of 1

Multiple MySQL Databases and mysql_select_db problem

Posted: Fri Jul 19, 2002 8:27 pm
by Packetrat
I've been working on one project for about six months now and recently decided to start on another when I ran into an aweful confusion: I don't remember setting up the first database and have no recollection of what I did to get the login and password set... I initially thought I would be able to use the same login and password for a second database but I can't get it to work from PHP (I can in the command dialog). What am I forgetting? Both databases are there and both have data in them, however I can only connect to the first. I'm pretty sure I didn't set any grants/permissions to any specific user since I'm relatively new to this. The error I get is the one I coded (echo...) when the mysql_select_db function does not return true. A friend of mine suggested that this might be caused by a connection already existing to the first project, however I'm not so sure that would be true since I have tested it upon reboot. I am using persistent connections (mysql_pconnect) though. The funny thing is that my first project still works fine. HELP!

Posted: Fri Jul 19, 2002 11:23 pm
by EricS
Your going to want to run the following command to see what the permissions are for the particular user your currently using.

Code: Select all

mysql> SHOW GRANTS FOR your_user@your_host;
Your looking for what appears after the "ON" keyword. A start "*.*" means this user can run all databases and all tables. A "my_bd.*" mean that user can access "my_db" database and all the tables in it. Make sure the user has a *.* or includes both databases your using. This will tell you once and for all it the problem is with the permissions set on the user.

Hope this helps,

Posted: Sat Jul 20, 2002 5:33 am
by twigletmac
I'd do what EricS said but something that can make debugging easier is to use mysql_error():

Code: Select all

mysql_select_db('db_name') or die(mysql_error());
Mac

Posted: Sat Jul 20, 2002 6:23 am
by Packetrat
Thank you for your help - I just needed to grant access to the database -> so, now the question is what is the difference between ALL PRIVILEGES and USAGE???

Posted: Sat Jul 20, 2002 7:24 am
by twigletmac