The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
|||
|
|||
Help with MySQL query
Hi folks,
I was wondering if anyone could help me with a query please? I have two mysql databases. The information is contained within the user table. db1 has information in 3 columns which I want to copy to the same columns in db2. And I want to do it with for all users on the forum. Any help would be great. Thanks! |
#2
|
|||
|
|||
I've managed to put this together but it's not working...
Code:
<?php $dba = mysql_connect('localhost', 'username_vbtest', 'password') or die(mysql_error()); $sql = " INSERT INTO username_vbtest.user ( post_thanks_user_amount, post_thanks_thanked_posts, post_thanks_thanked_times ) SELECT ( username_test.user.post_thanks_user_amount, username_test.user.post_thanks_thanked_posts, username_test.user.post_thanks_thanked_times ) FROM username_test.user "; $result = mysql_query($sql) or die(mysql_error()); mysql_close($dba); 'vbtest' is the destination database and 'test' is the source database. |
#3
|
|||
|
|||
What happens? Do you get an error?
You have username_test and username_vbtest in the code. |
#4
|
|||
|
|||
So I need to connect to two databases at once then?
Both databases have the same username and password if that makes it easier. So am I overcomplicating this? Would this also work? Code:
$dbh1 = mysql_connect($localhost, $username, $password); $dbh2 = mysql_connect($localhost, $username, $password, true); mysql_select_db('database1', $dbh1); mysql_select_db('database2', $dbh2); USE `database2`; INSERT INTO `database1`.`new_table`(`column1`,`column2`,`column3`) SELECT `old_table`.`column2`, `old_table`.`column7`, `old_table`.`column5` FROM `old_table` |
#5
|
|||
|
|||
I was just pointing out the code you posted didn't look like it was using the names of the databases you posted. As far as I know, if the databases are on the same server and the database user you're logging in as has the correct permissions on both, then you should be able to do it with something similar to what you originally posted. I'm not sure if what you posted is exaclty the right syntax, I'd have to try it.
|
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|