How to use 2 database in Php?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • shaif
    New Member
    • Mar 2008
    • 24

    How to use 2 database in Php?

    Hi all I am doing a module where I need to use 2 database . I start First database and select some data by using while loop. Inside While Lopp I need to open other Second database to insert some data from first BD, If any idea pls provide , I am using Php and SQL server. Many thx.
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    What have you tried so far?

    Comment

    • shaif
      New Member
      • Mar 2008
      • 24

      #3
      Originally posted by r035198x
      What have you tried so far?
      I connect with first database & after that I run a query which is getting data by while loop . and inside while loop i need to connect with other database to insert data into second DB. I tried normal connection such as
      [code=php]
      $con = mssql_connect(' localhost','php web','phpweb', 'TG') or die("Error: Could not connect to DB Server"); [/code]

      Is there any way to possibly solusion?
      Last edited by pbmods; Jul 25 '08, 02:42 AM. Reason: Added CODE tags.

      Comment

      • pbmods
        Recognized Expert Expert
        • Apr 2007
        • 5821

        #4
        Heya, Shaif.

        You should consider connecting to the second database *outside* the loop and using that connection resource where you need it.

        Note that mssql_query() takes a second parameter - the database connection resource (e.g., $con). Use this to direct which connection will receive the query (http://php.net/mssql_query).

        Comment

        Working...