0

Connect to 2 or more databases and select from tables in those databases.

I never needed this before, but now...i really do need! :)

I've googled but i could not find the right answer.

I need to connect to 2 or more database and then, if i need to, i want to select info from tables that are in one or more databases, using JOIN for example.

I have a user that has access to all databases and databases are all in the same host. I'm using mysqli.

How do i do this?

Thank you very much.

Pedro
  • 77
  • 8
  • 1
    This may be what you are looking for: [http://stackoverflow.com/questions/2132654](http://stackoverflow.com/questions/2132654) – Rasclatt Sep 01 '14 at 15:53
  • @Rasclatt thank you for your answer. I've seen that but it only says how to select. What about the connect? is it enough to connect to only one database? Thank you. – Pedro Sep 01 '14 at 15:57
  • I think you just use the one connection to access both. As long as the host contains both databases. – Rasclatt Sep 01 '14 at 16:02
  • @Rasclatt not woeking!! it gives me an error "(1142) SELECT command denied to user 'user_name'@'localhost' for table 'table_name'" – Pedro Sep 01 '14 at 16:09
  • Are you using shared hosting? – Rasclatt Sep 01 '14 at 16:10
  • Yes i'm paying one. Is not mine... Is that a problem? – Pedro Sep 01 '14 at 16:13
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/60404/discussion-between-rasclatt-and-pedro). – Rasclatt Sep 01 '14 at 16:16

1 Answers1

1
SELECT * from db1.table ...
LEFT JOIN db2.table ON ...
mariobgr
  • 2,143
  • 2
  • 16
  • 31