Re: Connections to two databases in the same script

From: Date: Thu, 08 May 2003 22:54:41 +0000
Subject: Re: Connections to two databases in the same script
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-146927@lists.php.net to get a copy of this message
----- Original Message ----- From: "Chris Cameron" <chris@upnix.com> To: <php-general@lists.php.net> Sent: Thursday, May 08, 2003 3:49 PM Subject: [PHP] Connections to two databases in the same script > 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 It's an interesting question but I don't think you can open two simultaneous connections to the same db server. You may have to reorder your code so that it works with just one connection... /* Connect to the mssql server*/ $dbConnect = mssql_connect($cDBHost, $cDBUser, $cDBPass); /* Select the wft_main database */ mssql_select_db($cDBMain, $dbConnect); $result_main = mssql_query("SELECT * FROM membership", $dbConnect); /* Select the wft_pcpump database */ mssql_select_db($cDBPCPump, $dbConnect); $result_pcpump = mssql_query("SELECT * FROM manufacture", $dbConnect); -Kevin

« previous php.general (#146927) next »