Re: [PHP] Opening more than one database at a time?

2002-01-20 Thread Ing. Daniel Manrique

It;'s entirely possible. Most database-related functions can take an 
optional link identifier parameter. You didn't use it, and in that case, 
database operations default to the last opened database connection. You 
can however do something like:

$dblink1=mysql_connect($server1,$user1,$password1);
$dblink2=mysql_connect($server2,$user2,$password2);

mysql_select_db($database_1,$dblink1); //for link 1
mysql_select_db($dblink2,$dblink2); //for link 2

$result1=mysql_query(SELECT * from whatever,$dblink1);

while ($row=mysql_fetch_array($result1)){
$query2=insert into secondtable values . 
$row[id].,.$row[whatever];
$result2=mysql_query($query2,$dblink2); //insert on database 2
}



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Opening more than one database at a time?

2002-01-20 Thread Miles Thompson

Jeff,

Can you let MySQL do the work for you, with INSERT ... SELECT? Here's the URL
http://www.mysql.com/doc/I/N/INSERT_SELECT.html

HTH - Miles Thompson


At 06:20 PM 1/20/2002 -0500, Jeff Lewis wrote:
I am trying to basically copy data from one database to another and am
wondering if it is possible to have more than one database open at a time.
So for example, I want to do something like this but am wondering if there
is a better way:

$dbcon = mysql_connect($db_server, $db_user, $db_passwd);  //Make source
connection
mysql_select_db($db_name);
//Select source db
$source_result = mysql_query(SELECT * FROM users); //Select all
info from users table
while ($row_cat = mysql_fetch_array($result)){
//Loop through and insert into new db
  //Insert into new database
}

So where I have Insert into new database this is where I want to take some
of the information from the source and insert into the new database (which
uses a different user name and password as well).

Any help would be greatly appreciated :)

Jeff



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Opening more than one database at a time?

2002-01-20 Thread Jeff Lewis

Not sure, the tables are in different databases with different users and
passwords.  I will look into it but the answer I got this afternoon
satisfied me :)

Jeff
- Original Message -
From: Miles Thompson [EMAIL PROTECTED]
To: Jeff Lewis [EMAIL PROTECTED]; [EMAIL PROTECTED]
Sent: Sunday, January 20, 2002 8:51 PM
Subject: Re: [PHP] Opening more than one database at a time?


 Jeff,

 Can you let MySQL do the work for you, with INSERT ... SELECT? Here's the
URL
 http://www.mysql.com/doc/I/N/INSERT_SELECT.html

 HTH - Miles Thompson


 At 06:20 PM 1/20/2002 -0500, Jeff Lewis wrote:
 I am trying to basically copy data from one database to another and am
 wondering if it is possible to have more than one database open at a
time.
 So for example, I want to do something like this but am wondering if
there
 is a better way:
 
 $dbcon = mysql_connect($db_server, $db_user, $db_passwd);  //Make source
 connection
 mysql_select_db($db_name);
 //Select source db
 $source_result = mysql_query(SELECT * FROM users); //Select all
 info from users table
 while ($row_cat = mysql_fetch_array($result)){
 //Loop through and insert into new db
   //Insert into new database
 }
 
 So where I have Insert into new database this is where I want to take
some
 of the information from the source and insert into the new database
(which
 uses a different user name and password as well).
 
 Any help would be greatly appreciated :)
 
 Jeff
 
 
 
 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 To contact the list administrators, e-mail: [EMAIL PROTECTED]







-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]