vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Code to copy data from one field to another. (https://vborg.vbsupport.ru/showthread.php?t=190042)

Jinovich 09-04-2008 07:39 PM

Code to copy data from one field to another.
 
So recently I accidently executed some sql code on my db changing 600 of my users email address to "abx@xyz.com" which has messed up a few things to say the least.

Now I can't install a backup of my forums as the incident occured about a month ago, instead I have found a backup close to the time before I corrupted the user table with the original email addresses in.

I was wondering if anyone could help write some code that would,

1) Query the active user table for users with the email address "abc@xyz.com"
2) Use the user id's from the previous query to look up the original email address from the user table from the backup.
3) Copy the email address from the backup user table into the currently active user table

Doesn't have to be fancy and plugin with vB I will settle for a simple script which connects directly to the db.

Would really appreciate if someone can help me do this.

Marco van Herwaarden 09-05-2008 06:17 AM

The following query should correc this. Replace 'userbackup' with the tablename you restored the old user table in.

[sql]UPDATE user AS u1, userbackup AS u2
SET u1.email = u2.email
WHERE u1.email = 'abx@xyz.com'
AND u1.userid = u2.userid;[/sql]

Not tested! Make sure to backup your database before running manual queries.

Jinovich 09-05-2008 08:36 AM

Thanks for this Marco, I have also been suggested this,
Code:

UPDATE
 user
LEFT JOIN
user2
ON
    user.userid = user2.userid
SET
    user.email = user2.email

This is obviously missing the conditionals that I would have to apply to my db as its been left so long (otherwise it will revert legit users who changed their email in the last month to their old email) but it would work for anyone else.

Marco van Herwaarden 09-05-2008 08:41 AM

That would (with conditional) also work, depending on your MySQL version.


All times are GMT. The time now is 07:10 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01031 seconds
  • Memory Usage 1,711KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_code_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (4)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete