I have information spread out across a few databases and want to put all the information onto one webpage using PHP. I was wondering how I can connect to multiple databases
You don't actually need select_db
. You can send a query to two databases at the same time. First, give a grant to DB1
to select from DB2
by GRANT select ON DB2.* TO DB1@localhost;
. Then, FLUSH PRIVILEGES;
. Finally, you are able to do 'multiple-database query' like SELECT DB1.TABLE1.id, DB2.TABLE1.username FROM DB1,DB2
etc. (Don't forget that you need 'root' access to use grant command)