SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Mar 2009
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Search and Replace in whole database? (IPB)

    I have no idea how to write SQL queries, that is why I am asking for help here. A user at one of my IPB forums wanted his account deleted but the problem is the quoted posts are not deleted with the accounts. So I need a query to replace his username with some other random string. Can any SQL guru cook something up? BTW the username is totally unique so it wouldn't affect any other fields.
    Thanks

  2. #2
    SitePoint Zealot superjacent's Avatar
    Join Date
    Jun 2007
    Location
    Melbourne, Australia.
    Posts
    121
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    REPLACE(str,from_str,to_str)

    Returns the string str with all occurrences of the string from_str replaced by the string to_str. REPLACE() performs a case-sensitive match when searching for from_str.

    Code:
    mysql> SELECT REPLACE('www.mysql.com', 'w', 'Ww');
            -> 'WwWwWw.mysql.com'
    This function is multi-byte safe.

    Some examples:

    Code:
    update TABLE_NAME set FIELD_NAME = replace(FIELD_NAME, ‘find this string’, ‘replace found string with this string’);
    
    update client_table set company_name = replace(company_name, ‘Old Company’, ‘New Company’)
    Is it really necessary to be altering the quoted username? I'm half assuming that the link will still be present to the original post.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •