0

I have written a query in PhpMyadmin to fetch data from two databases running in the same server, and is working fine. But I am not sure how to use this query in PHP code. This query contains RIGHT JOIN and other sub-queries. Even if I open two DB connections, how will I execute this query and which Connection should I use?

Eg.

Database A: Table: accountmaster (contains the profile details of the users, with IDs for City, State etc) Database B: All masters (City, State etc)

Query: fetching all profile entries by joining these two databases.

MyVision
  • 1
  • 2

1 Answers1

0

If you share your query, I think we could elaborate on more precise answers.

Probably your question is already answered here.

Firstly, you should use one connection from any database. I would prefer to connect to database A, once it contains the references to database B and makes sense for me to request join data from B.

As discussed in the link, it is necessary that the user has the privileges to execute the query.

Finally, it is just to write your query as discussed here - as a string - and pass it as a parameter to mysqli query.

Erme Schultz
  • 319
  • 5
  • 17