![]() |
[MySQL] How to import a column from db1.table to db2.table
Hello,
I've just downgraded my forum from vb4 to vb3, and would like to keep the "thanked" amount from old db. I looked into the old db and notice that "thanked" is a column in "user" table. So i would like to ask how can i move (or copy) that column from old database into the table of the new database? Also, is there anyway to plus 1 value in the "userid" field (of that column)? Because of i've used ImpEx and it's created a new admin with userid = 1, then my old admin account has userid = 2. Thank you. |
You'd have to create a new column with the exact datatype like the original column (if that istn't already done) then you'd have to create a php script, that queries every user row, builds a new query with updated userid (+1) in the WHERE clause to apply the sql query.
Could look something like this: Code:
SELECT userid, thankedamount FROM vb4_user Code:
UPDATE vb4_user SET thankedamount = ".$thankedamount." WHERE userid = ".$userid+1 |
I have ran this query in phpmyadmin and it's ok, but only for the user who has id=2, how to loop it?
Sorry because my php knowledge is bad. This is the query that i have used: Quote:
|
it's no mysql query at all :)
there needs to be a php script built around this... Can you tell me if the two vbulletin installations are stored in the same or in a different database? And tell me how the exact name of the column is where the amount of thanks is stored. |
Two forums are store in 2 different databases. I wrote as 'vb4forum' and 'vb3forum' as above.
And the 'thanked amount' column name is post_thanks_thanked_times Could you create a sample php page? |
1 Attachment(s)
This is my old convert-youtube script. I just adjusted some values and added a 2nd database.
This only works if username and password are the same for the 2 databases. open the file, enter your credentials at the top of the script. It works like $db1 reads, $db2 writes. So $db1 is your old db to read from, $db2 is the one where you want the thanks transferred to. Upload it into the root dir of your site (not forum root) so it can be accessed like "http://someurl.tld/transferthanks.php" and run it. didn't test it myself, if you're getting errors, report back. And I suggest to test it in a safe environment first. |
Thank for the file but when it's got error:
Quote:
Code:
$res['post_thanks_thanked_times'] = 0; Code:
else echo "Error: ".mysql_error()." (id: $id)<br />"; |
1 Attachment(s)
d'ouh, my bad.
Fixed |
Got this error:
Code:
Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1' at line 1 (id: 1) |
huh weird... change line 42 from:
PHP Code:
PHP Code:
|
Got this:
Quote:
|
Replace line 37 with this:
PHP Code:
|
It's Success. But it's look like it doesn't get thanked amount from database1. The thanked amount is from "write" db and being rewrite again with userid+1.
|
hum, well it should oO
did you re-check the database credentials? |
Quote:
Edit: never mind, I hadn't looked at the php file linked above where Disasterpiece had already handled the second database. BTW, I think this could be done via query something like: Code:
UPDATE db1.vb_user as old LEFT JOIN db2.vb4_user as new ON (old.userid = new.userid + 1) (But I haven't tested that exact query). That of course assumes that you've already created a "thanked" column in the new db....and that the dbs are on the same server. |
Quote:
Quote:
|
I think this is it:
Code:
UPDATE vb4forum.user as old LEFT JOIN vb3forum.user as new ON (old.userid = new.userid + 1) This sets the vb3forum database from the vb4forum database. I think what I posted above assumed that you were going from vb3 to vb4 (at least as far as the table prefixes were concerned). Speaking of which, if you have table prefixes you need to add them. |
I've down from vb4 to vb3, and there is no table prefix on 2 databases, i have full rights to modify them both.
I've just ran the query and there is an error: Quote:
|
Hmm...well, both lines together are supposed to be all one query and it looks like you just have the first line there.
|
yes, i've ran both of them together, but it shows up just 1 line for error.
|
The error looks like it's trying to execute only the first line. So I guess try this:
UPDATE vb4forum.user as old LEFT JOIN vb3forum.user as new ON (old.userid = new.userid + 1) SET new.post_thanks_thanked_times = old.post_thanks_thanked_times |
Okay, it's success :D kh99 you rock! Most of thanked amouths have right destination, i think i have to manual change few value.
Thank you all, both kh99 and Disasterpiece. |
All times are GMT. The time now is 04:12 AM. |
Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
![]() |
|
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|