Jump to content


Photo

Connecting to two databases on same server


  • Please log in to reply
2 replies to this topic

#1 stockton

stockton
  • Members
  • PipPipPip
  • Advanced Member
  • 319 posts
  • LocationMidrand South Africa

Posted 21 October 2006 - 11:26 AM

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?
Regards,
Alf Stockton   Programmer for rent.

#2 MCP

MCP
  • Members
  • PipPipPip
  • Advanced Member
  • 60 posts

Posted 22 October 2006 - 03:02 AM

when you connect, set new_link to be true (see http://ca3.php.net/m...sql-connect.php).

for example
<?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);
?>

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

#3 stockton

stockton
  • Members
  • PipPipPip
  • Advanced Member
  • 319 posts
  • LocationMidrand South Africa

Posted 22 October 2006 - 09:41 AM

Excellent. Thank you. ;D
Regards,
Alf Stockton   Programmer for rent.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users