简体   繁体   English

用PHP同时连接和查询两个Mysql数据库

[英]Connecting and querying two Mysql databases simultaneously with PHP

I'm intending to develope a web that interacts with three different Mysql databases in the same server. 我打算开发一个与同一台服务器中的三个不同的Mysql数据库进行交互的网站。 User and password are the same in all three databases. 用户和密码在所有三个数据库中都相同。
I want to use mysqli in procedural mode. 我想在过程模式下使用mysqli。
Some times I want to query just one databse, some times two of them, whatever. 有时我只想查询一个数据库,有时只查询两个。
What would it be the best way to connect with two of them and then, say, join two tables belonging to different databases? 与它们中的两个连接,然后联接属于不同数据库的两个表的最佳方法是什么?
Thanks in advanced! 提前致谢!

If the databases all reside in the same server, you can query any table in any database at any time that you have access to by prefixing it with the database name: 如果所有数据库都位于同一台服务器上,则可以在其有权访问的任何时间查询任何表,只需在其前面加上数据库名称即可:

SELECT *
  FROM database1.table1
  JOIN database2.table2 ON ...

If the databases are on two different servers or need different access rights, there's no way to do this. 如果数据库位于两台不同的服务器上或需要不同的访问权限,则无法执行此操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM