Jump to content

copy table columns from one db to another? (2 parts)


bnovak

Recommended Posts

Ok, lemme see if I can explain this so it makes some sense. It should be pretty simple - I can copy the tables INSIDE the db, but I have two db's that I need to copy a series of table columns between. Basically, I have two different frameworks on my site, one is a member application, and the second is a link directory. I want to copy the username and password from the member system to the linkdirectory system when a new user registers for a membership, but NOT vice-versa. Public can still register for the link directory though......(this way members only have one unified login and password across the site, make sense?)

 

These are on the same server

 

I'm basically trying to do a

 

$query = "INSERT INTO table2 (colA,colB,) SELECT colA,ColB FROM table1 "; 

 

which works if they are in the same db, but I don't know the trick is to go to another db.  Since this table is auto-increment, I'm also assuming that I can ignore the PK field and it will set one automatically?

 

Also, what would be the trick so that when this runs (I'll just put it in with some other php code I have on user update to the profile) it checks to make sure that it's not duplicating entries?

Link to comment
Share on other sites

this way members only have one unified login and password across the site, make sense?

 

Never thought about creating a shared database? Or make the second application work with the database of the first?

 

which works if they are in the same db, but I don't know the trick is to go to another db.

 

Documentation enlights the mind.

 

$query = "INSERT INTO database1.table2 (colA,colB,) SELECT colA,ColB FROM database2.table1 "; 

Link to comment
Share on other sites

Perfect - thanks ignace.

 

I have thought about creating a shared DB and will most likely go that route in the future for sanity's sake. This one is more of the "learning experience" though, and I haven't learned enough about joining two different software packages to one db.

 

Thanks again for the help.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.