0 Replies - 312 Views - Last Post: 30 April 2006 - 02:25 AM

#1 gayatri  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 2
  • View blog
  • Posts: 62
  • Joined: 13-February 06

Retrieve values in a database from another using php

Posted 30 April 2006 - 02:25 AM

Description: tested for mysql, may not work in any other database
<?php

$HOST="localhost";
$DB_USER="username";
$DB_PSSWD="password";
$DB_NAME="olddb";

$connection = mysql_connect($HOST, $DB_USER, $DB_PSSWD)or die('Could not connect to database');
$db = mysql_select_db($DB_NAME, $connection)or die('Could not select db');

function ChangeActiveDB($dbnew,$connection)
{
     global $db_url, $active_db;
     $db_url = trim($dbnew);

     if($db_url<>'')
     {
          $url = parse_url(trim($dbnew));
          unset($db);
          $db = mysql_select_db($dbnew, $connection)or die('Could not select db');
          $handle=mysql_query("select user from login");
          while($row=mysql_fetch_array($handle))
          {
               $getmyop[]=$row["user"];
          }
     }
     return $getmyop;
}

$dbnew="newdb";
$myoutput=ChangeActiveDB($dbnew,$connection);
print_r($myoutput);

?>


Is This A Good Question/Topic? 0
  • +

Page 1 of 1