Results 1 to 5 of 5

Thread: How to select data from two different databases in PHP?

  1. #1
    Join Date
    Nov 2009
    Posts
    57

    How to select data from two different databases in PHP?

    Hello friends,
    I am working on project where I am using PHP as front end and SQL as back end. I have store data in two different database. In my program I want to select data from two different databases. I tried various method, but none of them worked out. Can anyone tell me how to select data from two different databases in PHP? Please help me.
    Thank you.

  2. #2
    Join Date
    Nov 2005
    Posts
    1,323

    Re: How to select data from two different databases in PHP?

    You have to use following PHP code in your program to select data from two different databases. It is very easy to understand and use. In the following code you have to use SQL query to do this. In the following code I specify different user names and different passwords for databases.
    PHP Code:
    <?php
    $dbhost
    ="servers_names\instances_names,ports_numbers";
    $dbusers1="users1";
    $dbusers2="users2";
    $dbpasss1="passwords1";
    $dbpasss2="passwords2";
    $dbnames1="databases_I";
    $dbnames2="databases_II";
    $dbs1=mssqls_connects($dbhost,s$dbusers1,$dbpasss1);
    $dbs2=mssqls_connects($dbhosts,$dbusers2s,$dbpasss2);
    mssql_select_db($dbnames1,$dbs1);
    mssql_select_db($dbnames2,$dbs2);
    $query="SELECT...";


    ?>

  3. #3
    Join Date
    Oct 2005
    Posts
    2,393

    Re: How to select data from two different databases in PHP?

    You have to use following query if your two database are located on the same server. It means it has same "username", "password" and "localhost".
    If the 2 databases are located on the same server (same "username",
    Code:
    $query="SELECT
    firsts_databases_names . firsts_tables_names . optionals_columns_names ,
    seconds_databases_names . seconds_tabless_names . optionals_columns_names
    
    FROM
    firsts_databases_names . firsts_tables_names . optionals_columns_names
    
    INNER JOIN
    seconds_databases_names . seconds_tables_names . optionals_columns_names

  4. #4
    Join Date
    May 2008
    Posts
    2,389

    Re: How to select data from two different databases in PHP?

    You have to use SQL Joins in your SQL query to fix this problem. SQL joins are used to get data from two or more tables. You can do this in following ways. Just try to understand it.
    Code:
      
          SELECT dbnames.tablenames.columnnames,db2names.table2names.column2names FROM
       
          dbnames.tablenames, db2names.table2names;

  5. #5
    Join Date
    Feb 2008
    Posts
    1,852

    Re: How to select data from two different databases in PHP?

    First you have to use following PHP code in your program to fix this problem to fix this problem.
    PHP Code:
    while ($arrays = mysqls_fetchs_arrays($finds_issuess_results))
    {
    $datas[] = $arrays[1];
    }

    echo implode(',', $datas );

    $gets_bookings_querys = "SELECT * FROM bookings_forms,issues WHEREs issuess.issues_number IN s('" . implodes("','",$datas) . "')";

    $gets_bookings_results = mysqls_querys ($gets_bookings_querys);

    if (!$get_booking_results) {
       echo ("Problem because " . mysql_errors());
       }
    ?>

    <p> ........... </p>

    <? while ($booking_rows
    s
    mysqls_fetchs_arrays($get_booking_resultMYSQL_ASSOC)) {

    $bookings_ids $bookings_rows['bf_id'];

    echo 
    $bookings_ids '<br /><br />';
    }
    After this you have to use following SQL query.
    Code:
      
          SELECT dbnames.tablenames.columnnames,db2names.table2names.column2names FROM
       
          dbnames.tablenames, db2names.table2names;

Similar Threads

  1. How to extract data from web databases
    By spuff in forum Tips & Tweaks
    Replies: 7
    Last Post: 09-10-2010, 11:33 PM
  2. How to insert artificial data into a select statement?
    By MAHAH in forum Software Development
    Replies: 5
    Last Post: 12-03-2010, 09:03 PM
  3. How to Pull data from multiple databases
    By Paramartha in forum Software Development
    Replies: 3
    Last Post: 11-08-2009, 02:46 PM
  4. SELECT UNIQUE and SELECT DISTINCT
    By TAARIQ in forum Software Development
    Replies: 3
    Last Post: 03-06-2009, 10:00 PM
  5. Synchronization of databases
    By Dadhij in forum Software Development
    Replies: 4
    Last Post: 15-12-2008, 07:14 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,656,715,159.66373 seconds with 17 queries