[PHP] How can I query a data from two database in one statement?
Please give me the easy way. and How to connect 2 database to use it?
Thank you
[PHP] How can I query a data from two database in one statement?
Please give me the easy way. and How to connect 2 database to use it?
Thank you
It is possible to use database tables from different databases in one query, if your current connection is allowed to access both databases.
You just need to prefix every table name with the database name:
SELECT * FROM `databasename`.`tablename` ...
... LEFT JOIN `databasename_2`.`tablename`....
A 'database' in MySQL terms is a logical unit within a database server. To query tables from two separate databases, see Pekka's answer (though pleas note that restrictions apply - some JOINS might not work as intended etc. For more info see the MySQL docs.)
If you want to query two different database servers within the same statement, then the answer is that that isn't possible. You will have to create two separate connections, and query each of them individually.