本文介绍了mysql_connect()使用了两次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要我的脚本从两个不同的数据库中检索数据,所以我使用

mysql_connect()来打开两个连接。我只有一个服务器,用户和

密码,只有两个不同的数据库。简化,它将是:

$ con1 = mysql_connect($ server,$ user,$ pass);

mysql_select_db($ database1,$ con1);

$ res1 = mysql_query($ sql1,$ con1);


$ con2 = mysql_connect($ server,$ user,$ pass);

mysql_select_db($ database2,$ con2);

$ res2 = mysql_query($ sql2,$ con2);


print_r($ con1);

print_4($ con2);


do_things_with_res1();

do_things_with_res2();


mysql_close($ con2);

mysql_close($ con1);

问题是,无论我给链接和结果的名称是什么,每个

mysql_connect()会覆盖以前的。所以当我打电话给

do_things_with_res1()时,它实际上使用了$ database2。 print_r()部分显示

$ con1未被设置!

我浏览了php.ini并发现:


;最大链接数(持久性+非持久性)。

; -1表示无限制。

mysql.max_links = -1

我不能只使用一个连接,因为我有两个不同的组件

每次都不一定要调用。我疯了,所以我真的会感激任何提示。提前谢谢,

-

- álvaroG。Vicario - 西班牙布尔戈斯

- 发送到我邮箱的问题将是收费;-)

-

解决方案




I need that my script retrieves data from two different databases so I use
mysql_connect() to open two connections. I have only one server, user and
password, just two different databases. Simplified, it''d be:
$con1=mysql_connect($server, $user, $pass);
mysql_select_db($database1, $con1);
$res1=mysql_query($sql1, $con1);

$con2=mysql_connect($server, $user, $pass);
mysql_select_db($database2, $con2);
$res2=mysql_query($sql2, $con2);

print_r($con1);
print_4($con2);

do_things_with_res1();
do_things_with_res2();

mysql_close($con2);
mysql_close($con1);
The problem is that, no matter what names I give to links and results, each
mysql_connect() overrides the previous ones. So when I call
do_things_with_res1() it actually uses $database2. The print_r() part shows
that $con1 has been unset!
I browsed php.ini and found this:

; Maximum number of links (persistent + non-persistent).
; -1 means no limit.
mysql.max_links = -1
I can''t use only one connection because I have two different components
that are not necessarily called every time. I''m getting nuts so I''d really
appreciate any hint. Thank you in advance,
--
-- álvaro G. Vicario - Burgos, Spain
-- Questions sent to my mailbox will be billed ;-)
--

解决方案




这篇关于mysql_connect()使用了两次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-26 11:27