Could someone help with this question, how to create some PHP code for this,

What I want to do is to copy/manage data across from one applications database to another application's database.

For example, to copy across the

fields from one to the other.

Is there a way to capture this data as the mysql instruction is passed on to add/modify/delete data in a given field?

This is because, if a bridge is created at code level, another plugin (code) may be developed which isn't tied in to this code and yet it add/modifies/deletes data to a given field.

So by doing the capture at the database level, there is no need to worry about the code and having to watch out for code additions, modifications elsewhere all the time.


An instance would be

Define connection to data source database 1
Define connection to data destination database 2

Detect inctruction to database 1 to a given(defined) field A

If instruction is Add Data to field A
Then copy Data stream to be added to field A
And execute instruction to add the Data stream to database 2 field A

Field A can be "username" in each database


With such psuedocode, then additional fields can be added if it's working,

add email field in Database 1 to email field in database 2
add email field in Database 1 to email field in database 2


Then, if a delete instruction is sent, a similar instruction is sent to the database so that if "string" is existent in the given field, then delete

If it is a "modify" instruction, then a similar instruction is sent to the database so that if "string" is existent in the given field, then modify

Ofcourse, unlike add which does not rely on ID too much, modify and delete may at times rely on field ID. But in this case, if the field is predefined, then it would be a matter of only detecting the matching string in the field to modify or delete.

How can this be achieved?

9 Years
Discussion Span
Last Post by etlone

why don't you retrieve all the data and input it into table. then edit what you have to and submit it all to the next database. i can write a test script if you want to see what i mean. just let me know


Retrieving data in one go is not so much the problem

It's about each time a new account is created, so that the same data is created in the other application's database.

Here's the situation, I have a shopping cart and a CRM. Customer comes, signs up for an account on the shopping cart, I would like the customer's account details to also be copied across to the CRM.

If the customer logs into the account and makes changes to his profile, e.g. email, address, then those changes should also be copied across(modified) to the CRM's database fields set up to corrspond with the data fields in the cart

Such that one-off copying ends up not being helpful as it relies on scheduled manual updates whereas on-the-fly would be preferable.

Are you able to write such a script?


An examaple is this thread http://www.phpbuilder.com/board/showthread.php?t=10307121

The person there tried to put code together to move the data across when it's already in the database, but this means running through the entire database each time to synchronize data, which is a bit too much as it's always consuming a lot of resources, what is the database has so much data?
I think capturing would be a better way of managing data synchronization across two different application's databases.

$resource1 = mysql_connect(localhost, admin_plus, -----); 
$db = mysql_select_db(admin_plus, $resource1) 
               or die ("Couldn't select database."); 
$resource2 = mysql_connect(localhost,admin_image,-----); 
$db = mysql_select_db(admin_image, $resource2) 
               or die ("Couldn't select database."); 
$sql = "SELECT id FROM -members"; 
$query = mysql_query($sql, $resource1); 
for ($i=0;$i<($result = mysql_fetch_assoc($query));$i++) { 
    mysql_query("INSERT INTO users ('uid') VALUES('id') ($resource2"); 

?> back to top

Edited by mike_2000_17: Fixed formatting

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.