SQL Server Developer Center > SQL Server Forums > SQL Server Driver for PHP > connecting multiple databases with sqlsrv_connect
Ask a questionAsk a question
 

Answerconnecting multiple databases with sqlsrv_connect

  • Friday, November 06, 2009 4:07 AMelvi5 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    May I know how to connect to different tables from 2 different database instances in in one sqlsrv_connect function? I would like to query 2 different tables, one containing invoice information, and another one containing my customers' billing details. Please help!

    For example:

    select * from dbase1.invoices a, dbase2.customers b where a.cust_id = b.cust_id

Answers

  • Saturday, November 07, 2009 2:23 PMelvi5 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    I've actually found a solution to this problem. Don't specify any database name in sqlsrv_connect connection options. When you select tables, specify in the statement the full table name e.g. DB_Name.dbo.TBL_Name.

    At least it's working for those application that have needs to access to different databases.
    • Marked As Answer byelvi5 Saturday, November 07, 2009 2:24 PM
    •  

All Replies

  • Saturday, November 07, 2009 2:23 PMelvi5 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    I've actually found a solution to this problem. Don't specify any database name in sqlsrv_connect connection options. When you select tables, specify in the statement the full table name e.g. DB_Name.dbo.TBL_Name.

    At least it's working for those application that have needs to access to different databases.
    • Marked As Answer byelvi5 Saturday, November 07, 2009 2:24 PM
    •