heyy .
please tell me how to can i connect databases together . couz i am doing a project and i have to like some databases and get some information from at least 5 databases tables and display them in one page . can i do more than a connection to databases in one page and how , and if it is posible . how can i add information from one database to another database .????

Are you trying to join data from multiple tables in one database, or are you trying to join data across multiple tables in multiple databases?

i am trying to join data across multiple tables in multiple databases

In SQL assuming the current user has access to both databases:

SELECT 
  db1.table1.id AS `Id`,
  db1.table1.total + db2.table1.total AS `Total`
FROM 
  db1.table1
LEFT JOIN
  db2.table1 ON db1.table1.id = db2.table1.id
WHERE db1.table1.id = 1

If you are using the mysql driver, which you really shouldn't be unless you're on a very old version of mysql. You do not need to use mysql_select_db.
Open the connection to the server as you normally would and specify the full path to tables and fields using the database name. If the user can access both databases should return results just like anything else.

If you're using the mysqli driver, you again do not need to supply the default database. But if you don't you need to specify the full path to tables, db.table.col in every query just as with mysql.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.