I thought I had a solution for you until I read the documentation saying
that mysql_db_query() is now deprectiated. This is a concern since we have
been using the mysql_db_query() function (and still use with v.4.1.2) on our
site. This function works as following:

    // Connect to dbs
    $aaa_db = "aaa_dbname";
    $aaa_link = mysql_pconnect("localhost", "u", "p");

    $zzz_db = "zzz_dbname";
    $zzz_link = mysql_pconnect("remotehost", "u", "p");

    // Query dbs
    $aaa_result = mysql_db_query($aaa_db,"select * from apples", $aaa_link);
    $orchard = mysql_fetch_assoc($aaa_result);

    $zzz_result = mysql_db_query($aaa_db,"select * from zebras", $zzz_link);
    $zoo = mysql_fetch_assoc($zzz_result);

I played around with mysql_select_db() and found that I had to use a
persistant connection for the first database but could only use
mysql_connect for the second database.

    // Connect to db
    $aaa_db = "aaa_dbname";
    $aaa_link = mysql_pconnect("localhost", "u", "p");
    mysql_select_db($aaa_db,$aaa_link);

    $zzz_db = "zzz_dbname";
    $zzz_link = mysql_connect("remotehost", "u", "p");
    mysql_select_db($zzz_db,$zzz_link);

    // Query dbs
    $aaa_result = mysql_query("select * from apples", $aaa_link);
    $orchard = mysql_fetch_assoc($aaa_result);

    $zzz_result = mysql_query("select * from zebras", $zzz_link);
    $zoo = mysql_fetch_assoc($zzz_result);

Is there anyone out there who could suggest a safe and fail proof method of
connecting to two or more databases?

Rod


>"Php Freak" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> How would you keep two different MySQL connections to two different MySQL
databases (on two different MySQL servers) up and available with two
different pointers (id), and not need to always do "select_db()" to switch
between them?
>
> I thought that if I did this:
>
> ----------- php: -------------
> $aaa_link = mysql_pconnect("localhost", "u", "p");
> mysql_select_db("apples", $aaa_link);
>
> $zzz_link = mysql_pconnect("remotehost", "u", "p");
> mysql_select_db("zebras", $zzz_link);
> ------------------------------
>
> ... that I'd be able to access both pretty easily. Like this:
>
> ----------- php: -------------
> $aaa_result = mysql_query("select * from apples", $aaa_link);
> $orchard = mysql_fetch_assoc($aaa_result);
>
> $zzz_result = mysql_query("select * from zebras", $zzz_link);
> $zoo = mysql_fetch_assoc($zzz_result);
>
> $aaa_result = mysql_query("update apples set something='" .
$zoo['zebrafur'] . "'", $aaa_link);
> ------------------------------
>
> But it seems to tell me that $zzz_result is not a valid resource - unless
I do the select_db thing inbetween the two commands.
>
> Is there anyone doing this successfully?  Back-n-forth between two
databases?
>
> Thanks for any help.
>
>



-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to