Multiple MySQL Databases and mysql_select_db problem

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
Packetrat
Forum Newbie
Posts: 2
Joined: Fri Jul 19, 2002 8:27 pm

Multiple MySQL Databases and mysql_select_db problem

Post 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!
EricS
Forum Contributor
Posts: 183
Joined: Thu Jul 11, 2002 12:02 am
Location: Atlanta, Ga

Post 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,
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
Packetrat
Forum Newbie
Posts: 2
Joined: Fri Jul 19, 2002 8:27 pm

Post 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???
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Post Reply