How do I search between several db and present the result on the page itself?

Asked

Viewed 73 times

1

In the MySQL I have a database and inside it I have the table student, and would like to search in another bank that is identical to the first, however, with different information, and would like to know in which of the banks the pupil is created.

This search would display the result on the page itself, and I’m having this doubt and I’m not able to unroll it.

Obs: this code can be in php or JavaScript.

  • Create two different connections when executing the query specify the repective connections. You are using Mysqli or PDO?

  • Mysql, more would have another way, because if you have several schools would be several connections?

  • All Databases are on the same server?

  • Wouldn’t just be using the mysqli_select_db and select another database?

  • There’s a difference between asking for help and asking me to do it for you. Post the code: Manual on how NOT to ask questions.

1 answer

3


If the Databases are all on the same server, just enter the database name before the table name.

For example, assuming you have two Databases, DB1 and DB2:

Example of query consulting DB1:

SELECT * FROM DB1.Student WHERE ...

Example of query consulting DB2:

SELECT * FROM DB2.Student WHERE ...

Example of query using both:

SELECT s1.nome, s2.nome FROM DB1.Student as s1
JOIN DB2.Student as s2 ON s2.id = s1.id
  • Thank you leo_ap that gave me a light on how to solve my problem

Browser other questions tagged

You are not signed in. Login or sign up in order to post.