Connections to two databases in the same script
| From: | Chris Cameron | Date: | Thu, 08 May 2003 21:49:44 +0000 |
| Subject: | Connections to two databases in the same script | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-146922@lists.php.net to get a copy of this message | ||
I have a PHP script that needs to talk to two different databases (in
MSSQL) at the same time. Now, I thought this was possible with two
different link identifiers, but that doesn't seem to be the case.
I made a simplified script that has this behaviour:
<?php
/* Database */
$cDBHost = "DEVELOPER";
$cDBUser = "user";
$cDBPass = "password";
$cDBMain = "wft_main";
/* PC PUMP CONFIGURATION */
/* Database */
$cDBPCPump = "wft_pcpump";
/* Simply connect to the database */
$dMainConnect = mssql_connect($cDBHost, $cDBUser, $cDBPass);
/* Select the wft_main database */
mssql_select_db($cDBMain, $dMainConnect);
$dPCPumpConnect = mssql_connect($cDBHost, $cDBUser, $cDBPass);
/* Select the wft_main database */
mssql_select_db($cDBPCPump, $dPCPumpConnect);
mssql_query("SELECT * FROM membership", $dMainConnect);
mssql_query("SELECT * FROM manufacture", $dPCPumpConnect);
print("Finished");
?>
This errors with:
Warning: mssql_query() [function.mssql-query]: message: Invalid object
name 'membership'. (severity 16) in c:\inetpub\wwwroot\test.php on line 22
Warning: mssql_query() [function.mssql-query]: Query failed in
c:\inetpub\wwwroot\test.php on line 22
Finished
So, am I wrong in expecting this to work? Did I do something wrong?
Running Win2k, IIS, MSSQL 7 (MSDE) and PHP 4.3.1. And yes I'm certain both
those tables exist (in their respective DB).
Thanks,
Chris