简体   繁体   English

打开两个唯一的mysql连接?

[英]Opening two unique mysql connections?

I have two separate databases and I want to open a connection to both of them at the same time, they both have the same login details so I used the fourth parameter in the mysql_connect function so I could use both. 我有两个单独的数据库,我想同时打开两个数据库的连接,它们都有相同的登录详细信息,因此我在mysql_connect函数中使用了第四个参数,因此可以同时使用它们。

As such.. 因此..

$db1 = mysql_connect('host','user','pass',true);
mysql_select_db('db1', $db1);
$db2 = mysql_connect('host','user','pass',true);
mysql_select_db('db2', $db2);

When I use the $db1 resource in a mysql_query it works fine, however when I use $db2 it still tries to use the db1 database. 当我在mysql_query使用$db1资源时,它工作正常,但是当我使用$db2它仍然尝试使用db1数据库。

I know I can reference databases such as db.table but just wondering why this doesn't work? 我知道我可以引用db.table这样的数据库,但只是想知道为什么这不起作用?

If you don't provide an argument for the new_link parameter, an existing link will be returned; 如果不为new_link参数提供参数,则将返回现有链接;否则,将返回现有链接。 however, if you do but SQL safe mode is enabled, then it is ignored: 但是,如果您这样做但启用了SQL安全模式,则将其忽略:

bool new_link

If a second call is made to mysql_connect() with the same arguments, no new link will be established, but instead, the link identifier of the already opened link will be returned. 如果使用相同的参数再次调用mysql_connect(),则不会建立新的链接,而是将返回已打开的链接的链接标识符。 The new_link parameter modifies this behavior and makes mysql_connect() always open a new link, even if mysql_connect() was called before with the same parameters. new_link参数修改了此行为,并使mysql_connect()始终打开新链接,即使之前使用相同参数调用了mysql_connect()也不例外。

In SQL safe mode , this parameter is ignored. SQL安全模式下 ,将忽略此参数。

This could be the case. 可能是这种情况。

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

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