Jump to content

Connecting to two databases on same server


stockton

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?
Link to comment
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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.