如何使用php连接两个不同服务器上的两个数据库 [英] How to Connect two databases on two different servers using php

查看:66
本文介绍了如何使用php连接两个不同服务器上的两个数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 MySQL 中,我有两个不同的数据库——我们称它们为 A 和 B.

In MySQL, I have two different databases -- let's call them A and B.

数据库 A 驻留在服务器 server1 上,而数据库 B 驻留在服务器 server2 上.

Database A resides on server server1, while database B resides on server server2.

两台服务器 {A, B} 在物理上彼此靠近,但位于不同的机器上并且具有不同的连接参数(不同的用户名、不同的密码等).

Both servers {A, B} are physically close to each other, but are on different machines and have different connection parameters (different username, different password etc).

在这种情况下,是否可以将数据库 A 中的表与不同服务器的数据库 B 中的表进行连接?

In such a case, is it possible to perform a connection between a table that is in database A, to a table that is in database B of different servers?

如果是这样,我该如何在 php 中以编程方式进行处理?(我使用php,MySQLDB分别与每个数据库交互).

If so, how do I go about it, programatically, in php? (I am using php, MySQLDB to separately interact with each one of the databases).

推荐答案

我能想到的唯一方法,就是用所有不同的参数打开 2 个单独的连接(即实例化 2 个 PDO 对象),使用 2 个查询来查询所有将您需要的数据导入 PHP,然后在 PHP 上使用该数据.

The only way I can think of, is by opening 2 separate connections (i.e. instantiate 2 PDO objects) with all the different parameters, use 2 queries to query all the data you need into PHP, and then work with that on PHP.

这篇关于如何使用php连接两个不同服务器上的两个数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆