[PHP/SQL] Pull info from DB1 and insert into DB2
Hi all,
I need to pull 3 rows from database 1 (Username, Password, Email) and insert it into a second database which has completely different tables.
(Game user data to smf forums table)
I have never needed to do this before so im kind of clueless as what i need to do.
Is this possible to do within a php page, So they just click a button and they auto register with game info into the forums page, Or would i need to manually run something every so often?
I need to get this right before i try anything because the game has members and i dont want the trouble to correct a major screwup.
Any suggestions/guidance will be greatly appreciated.
Re: Pull info from DB1 and insert into DB2
You can do it in phpmyadmin if you're using MySQL database.
Click on the "Operations" tab.
Re: Pull info from DB1 and insert into DB2
Or you simply write the query yourself, it's not that difficult :wink:
MySQL AB :: MySQL 5.1 Reference Manual :: 13.2.4 INSERT Syntax
Depending on your database you can use subquerys to do it in one query or you'll have to load the data first from one database and then insert it into the other.
Re: Pull info from DB1 and insert into DB2
You can use subqueries on this one. Check the mysql website for more information.
I did something similar with a website. That website had to have a site, a forum and the game. All three with the same username and password. When ppl register at the site (or game), you should just add a row to the forum too. You have to use php. Remember that you than have to disable registering at the forum...
Daevius
Re: Pull info from DB1 and insert into DB2
I assume its only 3 fields but several records (more then 10 at least). In that case I would propably build a web application which would look like the following
GetRecords(from first table and database)
Do While Records <> Nothing
InsertRecord(to second table and database)
End While
please note that this is not actually code (which I guess is quite obvious).
Re: Pull info from DB1 and insert into DB2
It is also the most inefficient way possible since you need to switch databaseconnections for every record. Try doing that 20.000 times :icon6:
Re: Pull info from DB1 and insert into DB2
Select, variable, insert, ITS NOT THAT HARD!
Re: [PHP/SQL] Pull info from DB1 and insert into DB2
I think INSERT...SELECT would be better choice...
Code:
INSERT INTO tbl_name (field1, field2, field 3)
SELECT field1, field2, field3 FROM tbl2_name [ WHERE ] [ LIMIT ]