mysql_connect() used twice

From: Alvaro G Vicario (alvaro_QUITAR_REMOVE_at_telecomputeronline.com)
Date: 08/31/04


Date: Tue, 31 Aug 2004 12:24:31 +0200

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 ;-)
--


Relevant Pages

  • Re: T-SQL
    ... connections to two different databases. ... A stored procedure runs on one connection, ... multiple databases on the same instance of SQL Server. ...
    (comp.databases.ms-sqlserver)
  • RE: Q: Named pipes and Windows (integrated) authentication
    ... Trusted Connections or Windows Authentication is when the client uses ... A user needs first to be able to authenticate to the server either using: ... Creating databases is only acomplished after you've already connected. ...
    (microsoft.public.sqlserver.connect)
  • Unable to log into the database
    ... I am trying to connect to a database on a server on our network. ... two databases one is Interbase, ... I can open the connections in the server explorer connect ...
    (microsoft.public.vb.database)
  • Unable to log into the database
    ... I am trying to connect to a database on a server on our network. ... two databases one is Interbase, ... I can open the connections in the server explorer connect ...
    (microsoft.public.vb.database.ado)
  • Re: How do I read records from databases in two different connections ?
    ... If the two databases are on the same server, ... > I have 2 connections to two different databases. ... > cn1 has database db1 ...
    (microsoft.public.sqlserver.programming)