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
Username
Password
Address
Phone
email

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.

INSTANCE

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,
e.g.

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?

Recommended Answers

All 3 Replies

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.

<?php 
$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"); 
} 

mysql_close($resource1); 
mysql_close($resource2);    
?> back to top
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.