如何在PHP中同时连接到2个数据库 [英] How to connect to 2 databases at the same time in PHP

查看:101
本文介绍了如何在PHP中同时连接到2个数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图从1个PHP脚本连接到同一个MySQL实例上的2个数据库。

I am trying to connect to 2 databases on the same instance of MySQL from 1 PHP script.

此刻,我发现的唯一方法是

At the moment the only way I've figured out is to connect to both databases with a different user for each.

我在迁移脚本中使用它,其中我从原始数据库中获取数据并将其插入到新数据库中,因此我将遍历大量结果列表。

I am using this in a migration script where I am grabbing data from the original database and inserting it into the new one, so I am looping through large lists of results.

连接到1个数据库,然后尝试与同一个用户发起第二个连接,只是将当前数据库更改为新的

Connecting to 1 database and then trying to initiate a second connection with the same user just changes the current database to the new one.

任何其他想法?

推荐答案

将一个布尔值true作为可选的第四个参数传递给mysql_connect()。有关详情,请参见 PHP的mysql_connect()文档

You'll need to pass a boolean true as the optional fourth argument to mysql_connect(). See PHP's mysql_connect() documentation for more info.

这篇关于如何在PHP中同时连接到2个数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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