Jump to content

Archived

This topic is now archived and is closed to further replies.

stockton

Connecting to two databases on same server

Recommended Posts

Can one, from php, connect to two databases in the same script.
I need to write an application to process and display data from two seperate MSSQL databases both on the same server.
If I write the two routines(scripts) seperately and run them as such they both work but when I put them together in one script the second one is failing?

Share this post


Link to post
Share on other sites
when you connect, set new_link to be true (see [url=http://ca3.php.net/manual/en/function.mssql-connect.php]http://ca3.php.net/manual/en/function.mssql-connect.php[/url]).

for example
[code=php:0]
<?php
  $c1=mssql_connect("localhost","user","pass",true);
  mssql_selectdb("database1",$c1);

  $c2=mssql_connect("localhost","user","pass",true);
  mssql_selectdb("database1",$c2);

  $q1=mssql_query("select 'whatever1'",$c1);
  $q2=mssql_query("select 'whatever2'",$c2);
?>
[/code]

Just be sure to qualify all of your selectdb and query function calls with the proper connection resource.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.