* Mark D Wolinski ([EMAIL PROTECTED]) [000913 17:18]:
> Hi all,
>
> I'm using DBI to connect to a mySQL DB. I want to make two connections at
> the same time, as seen here:
>
> $DBI{database} = "DBI:mysql:db_a";
> $DBI{hostname} = A hostname;
> $DBI{username} = A Username;
> $DBI{password} = A Password;
>
> $DBI{db} = join (":",$DBI{database},$DBI{hostname});
> $db_driver = DBI->install_driver("mysql",$DBI{'username'},$DBI{'password'});
> $db_master = DBI->connect($DBI{'db'},$DBI{'username'},$DBI{'password'}, {
> RaiseError => 1}) || die $DBI::errstr;
>
> $DBI{forum_db} = "db_b";
> $db_forums = DBI->connect($DBI{'db'},$DBI{'username'},$DBI{'password'}, {
> RaiseError => 1}) || die $DBI::errstr;
> $db_forums->do( "use $DBI{forum_db}" );
>
> Basically, $db_forums can be any number of different db's depending upon
> certain veriables, but to get a persistant connection, I'm connecting to the
> server and then "use"ing the correct DB.
>
> The problem that I have is that the system works fine under normal uses.
>
> However, when I run it under mod_perl and Apache_DBI, the
> $db_forums->do{"use $DBI{forum_db}" ); also changes the $db_master
> reference as well.
>
> So my question is, am I doing something wrong here?
>
> $db_master will always point to one database, but $db_forums will point to
> different ones. I can "use" a the correct db before each reference to it,
> but that seems like an awful lot of useless calls.
>
> I can't figure out why changing $db_forums would affect $db_master.
Because it's the same handle! Since you're using the same connection
strings, Apache::DBI will connect the first time and cache the handle;
the second 'DBI->connect' call will return the already cached database handle.
You need to change the connect strings somehow so that Apache::DBI can
differentiate between the two. I've never tried it, but:
'DBI:mysql:dbname'
and
'DBI:mysql:database=dbname'
Perform the same function even though they are syntactically
different.
Good luck
Chris
--
Chris Winters
Senior Internet Developer intes.net
[EMAIL PROTECTED] http://www.intes.net/
Integrated hardware/software solutions to make the Internet work for you.