1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

MySQL Command to Replace Phone Number, Across ENTIRE WordPress Site

Discussion in 'MySQL' started by LindseyInteractive, Apr 9, 2014.

  1. #1
    Hello Guys,

    As you can see our website http://www.lindseyinteractive.com we have our phone number on several different pages, these are all using Wordpress and are in a database. However, we have just changed our phone number, so is there a way to run a SQL commend to replace the phone number we have on there with a new one?

    Thanks in advance.
     
    LindseyInteractive, Apr 9, 2014 IP
  2. adams26

    adams26 Well-Known Member

    Messages:
    18
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    108
    #2
    Well , you can change the phone numbers in one go via Update query . You need to define your table name and field name and run the query. Google it and you can do it with ease.
     
    adams26, Apr 11, 2014 IP
  3. pmf123

    pmf123 Notable Member

    Messages:
    1,447
    Likes Received:
    75
    Best Answers:
    0
    Trophy Points:
    215
    #3
    if your number is on a PAGE, chances are it is in a flat file on the server and you can do a simple text find and replace - or is your number listed on individual posts?
     
    pmf123, Aug 31, 2014 IP
  4. Krellen

    Krellen Greenhorn

    Messages:
    38
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    18
    #4
    You're going to want to refer to MySQL's REPLACE function to accomplish that (http://dev.mysql.com/doc/refman/5.0/en/replace.html).

    Some SQL like this will do the trick:
    UPDATE table_name
    SET your_field = REPLACE(your_field, 'old-phone-number', 'new-phone-number') WHERE your_field LIKE '%old-phone-number%'
    Code (markup):
    Obviously you would need to modify that to use the correct table, fields and phone numbers for your particular case.

    Hope that helps!
     
    Krellen, Sep 17, 2014 IP
  5. pmf123

    pmf123 Notable Member

    Messages:
    1,447
    Likes Received:
    75
    Best Answers:
    0
    Trophy Points:
    215
    #5
    is this in text on a wordpress type site?
     
    pmf123, Oct 16, 2014 IP
  6. dadaas

    dadaas Well-Known Member

    Messages:
    1,298
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    160
    #6
    You will need to use regex and run some kind of edit tool. Maybe it is possible to do with SQL, but you will need to use a code that will read a text and change number. How will i do it: i m not into SQL and MYSQL but i can code a bot that will read all pages and if he finds old number he remembers a page. After i collect all pages i will edit them and replace old number with new number. Ofcourse this method cost money.

    SQL method:
    I m not expert and i cant give you code. But you will need to run a search for a text that contains number, that can easy be done, even i can do this. But hard way is how to make a replace. How to replace old text, extract number and change it with new number. Is it even possible?
     
    dadaas, Oct 17, 2014 IP
  7. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #7
    Simple solution: download a backup of the database (the SQL-file), open it in a decent text-editor, and search/replace all instances of the phone-number. Upload back to the site.
     
    PoPSiCLe, Oct 18, 2014 IP
  8. dadaas

    dadaas Well-Known Member

    Messages:
    1,298
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    160
    #8
    That will work only if the database is small. There is no way he will open any larger database in txt editor. And i think that is anything above 50mb?
     
    dadaas, Oct 18, 2014 IP
  9. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #9
    Uhm, why not? Using vi, for instance, the file size is limited by the size of your /tmp-folder.
     
    PoPSiCLe, Oct 19, 2014 IP