开发者

Multiple database in single query is possible?

[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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜