stockton Posted October 21, 2006 Share Posted October 21, 2006 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? Quote Link to comment https://forums.phpfreaks.com/topic/24650-connecting-to-two-databases-on-same-server/ Share on other sites More sharing options...
MCP Posted October 22, 2006 Share Posted October 22, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/24650-connecting-to-two-databases-on-same-server/#findComment-112544 Share on other sites More sharing options...
stockton Posted October 22, 2006 Author Share Posted October 22, 2006 Excellent. Thank you. ;D Quote Link to comment https://forums.phpfreaks.com/topic/24650-connecting-to-two-databases-on-same-server/#findComment-112615 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.