Reputation: 794
I have two mysql databases with the same structure in each.
I want to take selected data from one db to the other.
One of the tables holds mutiple rows of data and I was looking at looping through the rows and doing inserts into the second db table but realised that as soon as I connect to the second db I will lose the connection to the first and the loop will fail.
Is the a robust and 'proper' way of doing theis rather than creating an array and then running an insert loop in the second db from the array?
currently I am using two different lots of credetials to access each db.
the API fuctons I am using are mysql_query and mysql_insert.
the reason i need to do this is I have a backend system that allows me to upload templates to the server, some are live and some are not.
the second db holds user details and details of any templates that they have selected.
btw I am working with php.
many thanks in advance and I hope I am not asking you to spoon feed me
cheers Barry
Upvotes: 1
Views: 118
Reputation: 410
You are able to use 2 connections simultaneously by using $link_identifier parameter in mysql_* functions:
$connection1 = mysql_connect('host1', 'user1', 'password1');
$connection2 = mysql_connect('host2', 'user2', 'password2');
...
$resource = mysql_query('SELECT .....', $connection1);
...
mysql_query('INSERT .....', $connection2);
...
mysql_close($connection1);
mysql_close($connection2);
Upvotes: 1
Reputation: 158007
new_link
.So, just create 2 connections returning their resources and then use these resource variables to tell mysql_query() which database to use
Upvotes: 0